Getting an Error on a Pop Up Box

mrjrobinson

New Member
Joined
Sep 6, 2017
Messages
8
Hi All,

I have created a Pop Up Box when a field contains a phrase, but whenever the cell its looking at is blank I get a "Run-time error '13': Type mismatch.

My code I have used is:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Worksheets("Member Tracker").Range("E3").Value = "Pay As You Go" Then
MsgBox ("Customer has to pay before entry")
End If
End Sub

Im guessing I need to add in something to say do nothing if the cell is blank, but stumped as to what to put. Any help with this is really appreciated.

Many thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Can you please explain what you are trying to do.
Also what sheet is this event running on?
 
Upvote 0
Can you please explain what you are trying to do.
Also what sheet is this event running on?

Hi!

So I have created a Member Tracker for a leisure centre. Part of this doc I have created a SEARCH field that when you enter in the membership number for the customer, along the top of the screen it will show the members information, Name, Membership Type, Expiry etc. So this information changes each time a membership number is entered into the search field. One thing I have added is when the cell E3 has the phrase Pay As You Go in it, I want a Pop Up Box to show up with the phrase "Customer has to pay before entry". This works all fine. But when I remove the membership number from the search box, makes field which shows the membership type blank and then the mismatch error.

Here are screenshots to backup what I have said above.

https://ibb.co/T2v1M0V
https://ibb.co/q0kkmLN
https://ibb.co/8xMBD7y

T2v1M0V
q0kkmLN
8xMBD7y
 
Upvote 0
At a guess cell E3 has a formula that returns #N/A when there is no number in the search box.
What cell is the Search box in?
 
Upvote 0
In that case try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "B3" Then
      If Target = "" Then Exit Sub
      If Target.Offset(, 3).Value = "Pay As You Go" Then
         MsgBox ("Customer has to pay before entry")
      End If
   End If
End Sub
 
Upvote 0
In that case try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "B3" Then
      If Target = "" Then Exit Sub
      If Target.Offset(, 3).Value = "Pay As You Go" Then
         MsgBox ("Customer has to pay before entry")
      End If
   End If
End Sub

Thanks for that, I have tried this and its not worked. I have attached a link to the work book above if you wanted to have a blast on it.
 
Upvote 0
That's because you are using an abomination called merged cells.
try
Code:
      If Target.Offset(, 2).Value = "Pay As You Go" Then
 
Upvote 0
That's because you are using an abomination called merged cells.
try
Code:
      If Target.Offset(, 2).Value = "Pay As You Go" Then

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Offset(, 2).Value = "Pay As You Go" Then
MsgBox ("Customer has to pay before entry")
End If
End Sub

Would this be what you mean?
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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