|
Sub Test()
MsgBox CreateSQL
End Sub
Function CreateSQL() As String
Dim arr As Variant, lngCol As Long, arrTemp As Variant
Dim strTableName As String, strFields As String, strValues As String
Dim strSQL As String
lngCol = ActiveSheet.Range("A2").End(xlToRight).Column
arr = Range(Cells(1, 1), Cells(3, lngCol))
strTableName = arr(1, 1)
arrTemp = Application.WorksheetFunction.Index(arr, 2, 0)
strFields = Join(arrTemp, ",")
arrTemp = Application.WorksheetFunction.Index(arr, 3, 0)
strValues = "'" & Join(arrTemp, "','") & "'"
strSQL = "Insert Into " & strTableName & "(" & strFields & ") Values(" & strValues & ");"
CreateSQL = strSQL
End Function
|
|