Hi friends,
I am a beginner to VBA. I wrote a code to basically compare two sheets of data by their brand name in column A. When they match, I want to subtract the corresponding values of sheet 1 and sheet 2 for same brand. I am using this code.
Please help , it is giving a Next without For error
The code is:-
Any help would be appreciated .. Thanks!
I am a beginner to VBA. I wrote a code to basically compare two sheets of data by their brand name in column A. When they match, I want to subtract the corresponding values of sheet 1 and sheet 2 for same brand. I am using this code.
Please help , it is giving a Next without For error
The code is:-
Code:
Option Explicit
Global Length1 As Integer, Length2 As Integer, i As Integer, j As Integer, k As Integer, Diff As Long
Public Sub mainQC()
i = 1
j = 1
k = 1
Length1 = Workbooks("Book1").Sheets("sheet1").Range("strtpoint1").End(xlDown).Row
Length2 = Workbooks("Book1").Sheets("sheet2").Range("strtpoint2").End(xlDown).Row
For i = 1 To Length1
For j = 1 To Length2
If Trim(StrConv(Workbooks("Book1").Sheets("sheet1").Range("A" & i).Value, vbProperCase)) = _
Trim(StrConv(Workbooks("Book1").Sheets("sheet2").Range("A" & j).Value, vbProperCase)) _
Then
Workbooks("Book1").Sheets("sheet3").Range("A" & k).Value _
= Workbooks("Book1").Sheets("sheet1").Range("A" & i).Offset(0, k).Value - _
Workbooks("Book1").Sheets("sheet2").Range("A" & j).Offset(0, (k + 1)).Value
Exit For
Next i
End If
End Sub
Any help would be appreciated .. Thanks!