Hi Everyone, I have issue with VBA with For next loops and verifying data.
Right now this macro does 2/3 of what I want, but I cannot get it to add the row on the end if it does not find it.
My goal is to check wb2 column "k" values against wb1 column "k" values and update if its their, and add if its not.
Am I over complicating this? I could really use some help here. Thanks
Right now this macro does 2/3 of what I want, but I cannot get it to add the row on the end if it does not find it.
My goal is to check wb2 column "k" values against wb1 column "k" values and update if its their, and add if its not.
Am I over complicating this? I could really use some help here. Thanks
VBA Code:
Public Sub Complete()
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Dim wb1 As Workbook, wb2 As Workbook
Set wb1 = Workbooks("data-first.xlsm")
Set wb2 = Workbooks("data-second.xlsm")
Dim wb1s As Worksheet, wb2s As Worksheet
Set wb1s = Workbooks("data-first.xlsm").Worksheets(1)
Set wb2s = Workbooks("data-second.xlsm").Worksheets(1)
Dim q As Long
For q = 3 To wb2s.Rows.Count
LastRowUpdate = wb2s.Cells(wb2s.Rows.Count, "K").End(xlUp).Row
For y = 3 To LastRowUpdate 'wb1 movement
If wb2s.Cells(y, 11) = wb1s.Cells(q, 11) Then
For i = 1 To 30 ' For the rows
If wb2s.Cells(y, i).Value <> wb1s.Cells(q, i).Value Then
wb1s.Cells(q, i) = wb2s.Cells(y, i)
End If
Next i 'End of the rows sub
ElseIf wb2s.Cells(y, 11) <> wb1s.Cells(q, 11) Then
LastRowMaster = wb1s.Cells(wb1s.Rows.Count, "K").End(xlUp).Row
For v = q To LastRowMaster
If wb2s.Cells(y, 11) = wb1s.Cells(v, 11) Then
For i = 1 To 30 ' For the rows
If wb2s.Cells(y, i).Value <> wb1s.Cells(v, i).Value Then
wb1s.Cells(v, i) = wb2s.Cells(y, i)
'here we can say add value to last column to show change. (same above)
End If
Next i 'End of the rows sub
Else:
End If
Next v
End If
Next y
Next q 'end wb2 movement
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub