Is there a way to loop by header name and not column number ? Below is my code to loop between sheets by column number to compare new to old data. It would make it more dynamic incase columns get moved around and I would not need to go back and redo the column numbers. Appreciate the help.
VBA Code:
Temp_RS.Activate
i = 2 'First Row Of Data On Temp_RS Sheet
Do Until Cells(i, 1).Value = ""
NotiNum = Cells(i, 2).Value
ScopeDesc = Cells(i, 3).Value
ScopeLoc = Cells(i, 4).Value
OpsMem = Cells(i, 5).Value
ScopeMem = Cells(i, 6).Value
ShortCode = Cells(i, 7).Value
ScopeCode = Cells(i, 8).Value
KeepSearching = True
RowNum = 4 'First Row Of Data On Available In R Systems Sheet
Current_RS.Activate
Do Until KeepSearching = False
If Cells(RowNum, 1).Value = ScopeNum Then
Cells(RowNum, 2).Value = NotiNum
Cells(RowNum, 3).Value = ScopeDesc
Cells(RowNum, 4).Value = ScopeLoc
Cells(RowNum, 5).Value = OpsMem
Cells(RowNum, 6).Value = ScopeMem
Cells(RowNum, 7).Value = ShortCode
Cells(RowNum, 8).Value = ScopeCode
KeepSearching = False
ElseIf Cells(RowNum, 1).Value = "" Then
Cells(RowNum, 1).Value = ScopeNum
Cells(RowNum, 2).Value = NotiNum
Cells(RowNum, 3).Value = ScopeDesc
Cells(RowNum, 4).Value = ScopeLoc
Cells(RowNum, 5).Value = OpsMem
Cells(RowNum, 6).Value = ScopeMem
Cells(RowNum, 7).Value = ShortCode
Cells(RowNum, 8).Value = ScopeCode
KeepSearching = False
Else
RowNum = RowNum + 1
End If
Loop
i = i + 1
Temp_RS.Activate
Loop
Last edited by a moderator: