Hi all, I am very new to VBA and struggling to make sense of it all!!
I am trying to help my wife with a spreadsheet she uses a lot. Basically I need to find a row in sheet 1 (Tracking) where Column B is the same in both and where column G in sheet 2 (BL) matches column K in sheet 1, and if so, update the data in sheet 1 column W with the data from sheet 2 column I. Now I have already had help with that bit and it works a treat
Thank you....
Now I am trying to highlight any rows in sheet 2 which do not match....
I have tried and it works on my test but when I run it on the actual spreadsheet (1 sheet has 8000 rows and one has 5000 rows) it takes forever and then crashes Excel! The OverwriteMatchedData function works fine its just the HighlightNotFound bit that breaks it, I was wondering if they can be combined?
Can anyone help?? It would be greatly appreciated. My code is below:
Sub OverwriteMatchedData()
Dim mSh As Worksheet, sSh As Worksheet
Dim i As Long, fRow
Set mSh = Worksheets("Tracking")
Set sSh = Worksheets("BL")
With sSh.Cells(1).CurrentRegion
For i = 2 To mSh.Range("B" & mSh.Rows.Count).End(xlUp).Row
fRow = .Parent.Evaluate("match(""" & mSh.Range("B" & i) & """&""" & mSh.Range("K" & i) & _
"""," & .Columns(2).Address & "&" & .Columns(7).Address & ",0)")
If Not IsError(fRow) Then mSh.Range("W" & i) = .Cells(fRow, 9)
Next
End With
MsgBox "Matches updated"
End Sub
Sub HighlightNotFound()
Dim Comp1, Comp2, x, y
Comp1 = Sheets("Tracking").Cells(Rows.Count, "B").End(xlUp).Row
Comp2 = Sheets("BL").Cells(Rows.Count, "B").End(xlUp).Row
For x = 2 To Comp1
For y = 2 To Comp2
If Not Sheets("Tracking").Cells(x, "B") = Sheets("BL").Cells(y, "B") And _
Sheets("Tracking").Cells(x, "K") = Sheets("BL").Cells(y, "G") Then
Sheets("BL").Range("A" & y & ":I" & y).Interior.Color = RGB(255, 255, 0)
End If
Next y
Next x
MsgBox "Not Found Rows in BL Updated", vbOKCancel
End Sub
Bookmarks