
Originally Posted by
stnkynts
fLoc is a range and needs to be treated properly.
fLoc = sh2.Range("E:E").FindNext(fLoc)
'should be
Set fLoc = sh2.Range("E:E").FindNext(fLoc)
Also change this:
Loop While fAdr <> fLoc.Address And Not fLoc is Nothing
I changed the code per your suggestions and am still getting the same result as before. It is skipping any rows that have the date listed more than once
New code:
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, fLoc As Range
Dim fAdr As String
Set sh1 = Sheets("Back Orders")
Set sh2 = Sheets("BO Save")
lr = sh1.Cells(Rows.Count, 5).End(xlUp).Row
Set rng = sh1.Range("E7:E" & lr)
For Each c In rng
Set fLoc = sh2.Range("E:E").Find(c.Value, , xlValues)
If Not fLoc Is Nothing Then
fAdr = fLoc.Address
Do
If Trim(c.Offset(0, -4).Value) = Trim(fLoc.Offset(0, -4).Value) Then
If fLoc.Offset(1, 0) = "" And fLoc.Offset(1, -4) <> "" Then
c.Offset(1, 0).EntireRow.Insert
fLoc.Offset(1, -4).Copy c.Offset(1, -4)
c.Offset(1, -4).Columns("A:J").Merge
End If
Exit Do
End If
Set fLoc = sh2.Range("E:E").FindNext(fLoc)
Loop While fAdr <> fLoc.Address And Not fLoc Is Nothing
End If
Next
Bookmarks