Hi there!!
I tweaked your code a little, and it is working fine now. Please use the following code :
Sub Rowformat()
Dim Sht1Rng As Range
Dim Sht2Rng As Range
Dim D As Range
Dim mainSht As Worksheet
Dim backUpSht As Worksheet
Dim rngToCopyTo As Range
'Compares the ID cell in both worksheets to each other
Set mainSht = Worksheets("Main")
Set backUpSht = Worksheets("Backup")
Set Sht1Rng = Worksheets("Main").Range("B6", Worksheets("Main").Range("B65536").End(xlUp))
Set Sht2Rng = Worksheets("Backup").Range("B6", Worksheets("Backup").Range("B65536").End(xlUp))
For Each B In Sht1Rng
Set D = Sht2Rng.Find(B.Value, LookIn:=xlValues)
'If same value found in col B of "Backup" sheet then copy
If Not D Is Nothing Then
'Sheets("Backup").Select
backUpSht.Range(backUpSht.Cells(D.Row, 1), backUpSht.Cells(D.Row, 58)).Copy
'Sheets("Main").Select
Set rngToCopyTo = mainSht.Range(mainSht.Cells(D.Row, 1), mainSht.Cells(D.Row, 58))
rngToCopyTo.PasteSpecial xlPasteFormats
'B.Resize(, 58).Copy Worksheets("Main").Range(Cells(B.Row, 1), Cells(B.Row, 58).PasteSpecial XlPasteFormats
End If
Set D = Nothing
Next B
End Sub
Thanks,
Vikas
Bookmarks