vba type mismatch only on command button

Hake

New Member
Joined
May 23, 2012
Messages
5
Hi,

Can someone please help.

I have the exact same code assigned to 'image_click' and 'commandbutton_click'.

'commandbutton_click' returns a 'type mismatch error' whilst 'image_click' does not.

Code:
On Error GoTo Message
If Not TextBox7.Value = vbNullString Then
Sheet1.Range("AN17") = "=" & TextBox7.Value
Else
Sheet1.Range("AN17") = ""
End If
GoTo Resumenow
Message:   MsgBox "Please check Quantities only contain numbers and - + * ", vbExclamation, "QUANTITY ERROR"
TextBox7.SetFocus
Exit Sub

It's a simple textbox in a userform.
If I type in say '20-2' and click on the image button, the cell will show '18'.
If I click on the commandbutton it goes straight to Message error.
However the cell contents does show '18'

I'm running MSO 2010 - Win 10

Any feedback would be appreciated.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Where is your Resumenow line? Is it present in both codes? Could that be the error that it's encountering, Resumenow is missing from the button code? Have you tried stepping thru the code with F8 and seeing what happens?

Especially if you have the same code repeated, I would make a sub in a module to do the work and have the buttons call that sub. That way, if you have to change the code, you're only changing it and debugging it once.
 
Upvote 0
Thanks Bill - your suggestion to step through it made me actually step through ALL the code and not just that part of it.
It's a large workbook and has quite a few ="" in both the VBA code and on the actual sheets.
I'm still trying to find it, but somewhere a "" is being thrown into a cell that the above also references on another UserForm.
Thus the mismatch. Laziness on my side. Should be using =vbnullstring not = "".
Cheers and have a nice xmas.
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

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