(Solved) – Need to update selected columns in Excel [closed]

  • by
(solved)-–-need-to-update-selected-columns-in-excel-[closed]

I need to update selected columns, I have code to do that but is updating all columns starting with i=7 to the columns I have selected, it is updating even the hidden columns. I will paste the code i work with.
I have tried to update using different code but can’t test it because it will mix up the data in the sql database. Can someone help me with some line of code.For example i need to update only column 149,150,151 and with my code it will be updated all columns from 7 to 151.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Sub btnUpdate_in_database_group_PD_UND()

ActiveSheet.Unprotect

Dim Connected As Boolean

Dim count As Integer
Dim i As Integer

Sheets("PD_UND").Select

count = Range(Range("A7"), Range("A7").End(xlDown)).count
If Connected Then


    For i = 7 To (7   count)
        If (sqlKeyExist(Range("A"   CStr(i)).Text)) Then

            'MsgBox "Update"
'ActiveSheet.Unprotect
            sqlUpdate CStr(i)

     End If

End Sub

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Sub sqlUpdate(i As String)

    Dim strUpdate As String


    strUpdate = "SET DATEFORMAT DMY; UPDATE lletsData " & _
                                "SET Date = " & EmptyDate2NullStr(Range("E"   i).Value) & ", " & _
                                "number = '" & Range("F"   i).Text & "', " & _
                                "period_mmm_yy = '" & Range("T"   i).Text & "', " & _
                                "Year = '" & Range("U"   i).Text & "', " & _
                                "FY = '" & Range("V"   i).Text & "' "



strUpdate = strUpdate & "WHERE _number = '" & Range("A"   i).Text & "'"




    ' If connected run query and disconnect
    con2.Execute strUpdate



End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *