Type Mismatch

K

Karen53

Hi,

I am getting an error 13: Type Mismatch and don't understand why. Would
someone clarify this for me?

Sub SaveItems(AmountCol, Choice, ItemAmount)

Dim ws As Worksheet
Set ws = Tablespg

With ws

With .Range(AmountCol & Choice)
.Value = Val(ItemAmount)
.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* " -
"??_);_(@_)"
End With

End With

End Sub

The error occurs at the .NumberFormat statement. ItemAmount is a value
obtained from a textbox then converted to a number in the .Value statement.
 
B

Bob Phillips

What is in AmountCol, Choice and ItemAmount. My guess is that one of those
is invalid

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
A

Andrew Taylor

The minus sign in the .NumberFormat line makes
no sense - the type mismatch is complaining about
that, because you're trying to subtract one string
from another. You just need something like:

..NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(*??_);_(@_)"
 
J

Jean-Yves

Hi Karen,

After test, it comes from the string format argument itself.
OK "_(* #,##0.00_);_(* (#,##0.00))"
Not OK "_(* #,##0.00_);_(* (#,##0.00);_(* " - "??_);_(@_)"

Try recording a macro to get the format argument correctly set.
Regards

JY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Changed variable value 6
CONCATENATE code 2
save textbox as number wth Cint? 7
Textbox Value Changes 3
Copy from on eworkbook to another 2
type mismatch error 2
I need Help Please 3
Sheet protection 1

Top