I know I must be missing something silly here. I keep getting the error message, "Run-time error '1004': Application-defined or object-defined error" on the bolded line below. Can't seem to figure out what I'm doing wrong.
Code:
Sub EEE_Reformat()
Dim wb1 As Workbook
Dim cell1 As Range, rng1 As Range, cell2 As Range, rng2 As Range
Dim Cel As Range
Dim Sht1 As Worksheet
Dim Sht2 As Worksheet
Set wb1 = ThisWorkbook
Set Sht1 = wb1.Sheets("Sheet1")
Set Sht2 = wb1.Sheets("Sheet2")
Set Cel = Sht1.Range("A2")
Set rng1 = Range(Cel, Cel.Offset(Sht1.Cells.Rows.Count - Cel.Row, 0).End(xlUp))
Set Cel = Sht2.Range("A2")
Set rng2 = Range(Cel, Cel.Offset(Sht2.Cells.Rows.Count - Cel.Row, 0).End(xlUp))
[COLOR=#ff0000][B] If Sht1.Cells(i, 13) = "" Then[/B][/COLOR] 'if current cell in column 13 is empty then...
For Each cell2 In rng2 'for each cell in range 2 defined above (column A in Sheet2)...
For Each cell1 In rng1 'for each cell in range 1 defined above (column A in Sheet1)...
If cell2.Value = cell1.Value And cell2.Offset(0, -5) = cell1.Offset(0, -1).Value Then 'if the value of cell2 equals the value of cell1 AND the value of cell2 (offset by 5 columns) equals the value of cell1 (offset by 1 columns) then...
cell1.Offset(0, -12).Value = cell2.Offset(0, 1).Value 'from to Sheet1 column B to Sheet2 column M
cell1.Offset(0, -13).Value = cell2.Offset(0, 2).Value 'from to Sheet1 column C to Sheet2 column N
Exit For
End If
Next
Next
End If
End Sub
Last edited: