Type Mismatch

Ed Raymond

New Member
Joined
Mar 2, 2005
Messages
16
Hello,

New to VBA, why are the following lines a type mismatch?

Set Impact = Worksheets("Sheet2").Range("C4:C38")
If Impact = Empty Then
MsgBox "No Calculation Possible", vbExclamation

When I run debug, the MsgBox line gives me the error.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Ed

Are you sure the line causing the error is the 3rd one?

And are you sure you've posted all the code?

What you've posted so far won't even compile because it's missing an End If.

If that's added then the error occurs on the If statement not the message box part.
 
Upvote 0
Norrie,

Thank you. Here is evrything.

Private Sub GardCalc_Click()
'Error Handling ... no impact data
Dim Impact As Range
Set Impact = Worksheets("Sheet2").Range("C4:C38")
If Impact = Empty Then
MsgBox "No Calculation Possible", vbExclamation
Else: MsgBox "Ready to Rock"
End If
End Sub
 
Upvote 0
Ed

You can't use Empty like that.

What are you actually trying to do?
 
Upvote 0
I think you're trying to see if there is any data in the range right? And if no data in the range, then...msgbox..

instead of
If Impact = Empty Then

try

If Worksheetfunction.CountA(Impact) = 0 Then

Hope this helps.
 
Upvote 0
Ed

You can't use Empty like that.

What are you actually trying to do?

I am trying to make sure the user has entered "values". The spreadsheet operator enters an X if an event is a failure and a O if it is a pass. The spreadhseet counts the number of X events and using a formula, calculates the point where 50 percent pass and 50 percent fail. I am trying to automate the calculation so the operator simple enters the "event" and the spreadsheet does the rest.
 
Upvote 0
I think you're trying to see if there is any data in the range right? And if no data in the range, then...msgbox..

instead of
If Impact = Empty Then

try

If Worksheetfunction.CountA(Impact) = 0 Then

Hope this helps.

Jon,

That works, what does CountA do?
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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