Hello I doing an update from Excel to SQL but the code only works for 1 row. I want to update multiple rows or you could say all rows which are on Excel I have loaded
see the below code
VBA Code:
Sub UpdateTable()
Dim cnn As ADODB.Connection
Dim uSQL As String
Dim LR, LC As Long
Dim Group, Category As String
Dim itcode As Integer
' this is only for active cell i want for all cell in sheet which is on A column
Dim rngname As Range
Set rngname = ActiveCell
Set cnn = New Connection
itcode = ShCustomers.Cells(rngname.row, 1)
Group = "'" & ShCustomers.Cells(rngname.row, 2) & "'"
Category = "'" & ShCustomers.Cells(rngname.row, 3) & "'"
cnnstr = "Provider=SQLOLEDB; Data Source=MAK-SYS;Initial Catalog=db_bckupserver_test_sys;User ID=sa;Password=Rehman@123;Trusted_Connection=No"
cnn.Open cnnstr
uSQL = "UPDATE mak_items_chart SET [Group] = " & Group & " WHERE itcode = " & itcode
cnn.Execute uSQL
cnn.Close
Set cnn = Nothing
End Sub
I want to loop it but I don't understand how I can add a loop which will update all the records into SQL
Here is the image with modified code