Countif in macro

rdenessen

New Member
Joined
Jul 4, 2012
Messages
6
Hi,

I have a macro which selects a worksheets, copies it to a new book, removes unneeded rows based on certain criteria and exports it to a txt file.
My knowledge of macro's is limited, so it is mostly thanks to google and you guys here.

Now, I want to add a check at the start of my macro, basically, the condition is:
if COUNTIF(BB7:BB200;1)=1 then Stop the macro else continue with the next step. How would I build this in VB into the macro?

Thanks!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try

Code:
If WorksheetFunction.CountIf(Range("BB7:BB200"), 1) = 1 Then Exit Sub
 
Upvote 0
Hi, a follow up question:
Is it possible to include a message (pop-up) in this? This to make sure the user acknowledges the error.

Thanks!
 
Upvote 0
Try

Code:
If WorksheetFunction.CountIf(Range("BB7:BB200"), 1) = 1 Then
    MsgBox "Your message here"
    Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,206,711
Messages
6,074,475
Members
446,071
Latest member
gaborfreeman

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