I'm trying to have my macro check if cells in a row on two different sheets match. I'm able to get it to work using And & Offset, but I'd like to know if there's another method to accomplish the same thing in a shorter code. This is essentially what I've got so far:
Dim Sheet1 as Worksheet
Dim Sheet2 as Worksheet
Dim iCells as Range
Dim iRows as Range
Dim iLastRow As Integer
Dim iMatch as Boolean
Set Sheet1 = ThisWorkbook.Sheets("Sheet1")
Set Sheet2 = ThisWorkbook.Sheets("Sheet2")
iLastRow = Sheet2.Range("A2").End(xlDown).Row
Set iRows = Sheet2.Range("A2:A" & iLastRow)
iMatch = False
For Each iCells In iRows
If iCells.Value = ActiveCell.Value Then
If iCells.Offset(0, 1).Value = ActiveCell.Offset(0, 1).Value And iCells.Offset(0, 2).Value = ActiveCell.Offset(0, 2).Value And iCells.Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value And iCells.Offset(0, 4).Value = ActiveCell.Offset(0, 4).Value Then
****************
This last line is the one I'm trying to shorten. In reality, it goes on until .Offset(0,7) and the two sheets are also in separate workbooks. Aside from that, the basis is the same and I'm just trying to find a way to shorten the code.
I've tried doing this by using the value of the range (i.e. Range(iCells, iCells.Offset(0,7)).Value ), but I couldn't get it to work as I thought it would.
Does anybody have any thoughts? I'm getting a little tired of repeatedly using "Offset And Offset And Offset And Offset". Thanks!
Dim Sheet1 as Worksheet
Dim Sheet2 as Worksheet
Dim iCells as Range
Dim iRows as Range
Dim iLastRow As Integer
Dim iMatch as Boolean
Set Sheet1 = ThisWorkbook.Sheets("Sheet1")
Set Sheet2 = ThisWorkbook.Sheets("Sheet2")
iLastRow = Sheet2.Range("A2").End(xlDown).Row
Set iRows = Sheet2.Range("A2:A" & iLastRow)
iMatch = False
For Each iCells In iRows
If iCells.Value = ActiveCell.Value Then
If iCells.Offset(0, 1).Value = ActiveCell.Offset(0, 1).Value And iCells.Offset(0, 2).Value = ActiveCell.Offset(0, 2).Value And iCells.Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value And iCells.Offset(0, 4).Value = ActiveCell.Offset(0, 4).Value Then
****************
This last line is the one I'm trying to shorten. In reality, it goes on until .Offset(0,7) and the two sheets are also in separate workbooks. Aside from that, the basis is the same and I'm just trying to find a way to shorten the code.
I've tried doing this by using the value of the range (i.e. Range(iCells, iCells.Offset(0,7)).Value ), but I couldn't get it to work as I thought it would.
Does anybody have any thoughts? I'm getting a little tired of repeatedly using "Offset And Offset And Offset And Offset". Thanks!