只做备注
Sub general_sql_macro() Sql = "" column_name = "user_count" Sql = "insert into `mytable` (date," + column_name + ") values " For Row = 1 To 1000 date_str = CStr(Sheets("Sheet1").Cells(Row, 1).Value) If date_str = "" Then Exit For End If If Row <> 1 Then Sql = Sql + "," End If Value = Sheets("Sheet1").Cells(Row, 2).Value insert_value = "('" + date_str + "'," + CStr(Value) + ")" Sql = Sql + insert_value Next Row Sql = Sql + " on DUPLICATE KEY UPDATE " + column_name + "=values(" + column_name + ")" Sheets("Sheet1").Cells(5, 5).Value = Sql End Sub