Countif Range selection problem

airportzoo

New Member
Joined
Jun 24, 2011
Messages
14
Hello

This bit of code sits in the middle of a big bit of code, but I'm getting the error
"Compile error:
Type mismatch"
on the
Code:
"O2:O200"
bit.

Code:
If Application.WorksheetFunction.CountIf("O2:O200", "#REF!") >= 1 Then
    MsgBox("There is a problem with the database. The repair macro will run to fix this. Then send the text again.", vbOKOnly, "Error") = vbOK
    Run macro2
    Exit Sub
    Else

The idea is that before the main code in the macro executes, this bit of code will make sure there are no #REF! errors in column O, and if there are a msgbox will come up and indicate a problem and then execute another macro to repair the #REFs.

If anyone can provide some direction, that would be great!

Thanks!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I'm not sure that this will work as intended but you need Range

Code:
If Application.WorksheetFunction.CountIf(Range("O2:O200"), "#REF!") >= 1 Then
 
Upvote 0
Thanks Peter. That problem is solved but I'm getting another compile error:
"Function call on left-hand side assignment must return Variant or Object."

I've seen plenty of error messages but that one is new to me and the help files don't help....
 
Upvote 0
Maybe you need something like this

Code:
If Application.WorksheetFunction.CountIf(Range("O2:O200"), "#REF!") >= 1 Then
    If MsgBox("There is a problem with the database. The repair macro will run to fix this. Then send the text again.", vbYesNo, "Error") = vbYes Then
        Run macro2
        Exit Sub
    Else
'?
   End If
Else
'more code
End If
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,669
Members
448,977
Latest member
moonlight6

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