If macro help

EOAEvan

Active Member
Joined
Sep 20, 2007
Messages
399
I have the below macro that compares two lists to each other. You paste the New and Old lists into columns B and H and it tests for any accounts added to the new list and also for accounts that were dropped from the old list. I need to add a test that if it finds no changes to not perform the part where it adds the countif formula and skips to the second part of the macro to test for the dropped. And again if it finds no changes skip the portion of the code that adds forumals. I hope this makes sense. Please let me know if I need to clarify anything!

Code:
Sub CompareColumnB2H()

Application.Calculation = xlCalculationManual

Dim LstRwB&, LstRwH&, LstRwM, LstRwP, bVal As Range

LstRwB = Cells(Rows.Count, "B").End(xlUp).Row
LstRwH = Cells(Rows.Count, "H").End(xlUp).Row

For Each bVal In Range("B3:B" & LstRwB)
  If Application.WorksheetFunction.CountIf(Range("H3:H" & LstRwH), bVal) = 0 Then _
    Cells(Rows.Count, "M").End(xlUp)(2).Value = bVal
Next

For Each bVal In Range("H3:H" & LstRwH)
  If Application.WorksheetFunction.CountIf(Range("B3:B" & LstRwB), bVal) = 0 Then _
    Cells(Rows.Count, "P").End(xlUp)(2).Value = bVal
Next


LstRwM = Cells(Rows.Count, "M").End(xlUp).Row
LstRwP = Cells(Rows.Count, "P").End(xlUp).Row

Range("N3").Value = "=vlookup(m3,b$3:c$50000,2,false)"
Range("N3").AutoFill Destination:=Range("N3:N" & LstRwM)
Range("Q3").Value = "=vlookup(p3,h$3:i$50000,2,false)"
Range("Q3").AutoFill Destination:=Range("Q3:Q" & LstRwP)

Application.Calculation = xlCalculationAutomatic

Range("M3:Q50000").Value = Range("M3:Q50000").Value

    Sheets.Add After:=Sheets("Paste Here")
    ActiveSheet.Name = "Output"
    
    Sheets("Paste Here").Columns("M:Q").Copy
    Sheets("Output").Paste
    
    Sheets("Output").Move

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I thought it would take something more complicated but it seems I have got a simple If statement to work. Thanks to those that took a look.
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,391
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top