(Updated) I'm new to VBA and have been trying various things for hours but I can't seem to figure out how to simply multiply a decimal user input of 1.1 by the cell value of C1 (71388.92). Here is what I've tried last:
Private Sub CommandButton1_Click()
Dim myValue As Variant
myValue = InputBox("Prompt", "Title")
Range("C5").Value = myValue * Range("C1")
End Sub
I get a runtime error '13'- Type mismatch perhaps because cell C1
's value is derived from a json web query. I've tried Variant, Double, Single, Long and Data Types Decimal, Number and Currency.
Download link: https://www.dropbox.com/sh/tg5f2a71k9jy6xq/AACrhI9_6VG8vJkDr0QVCbSUa?dl=0
Found Solution:
The error with the InputBox
accepting a decimal entry lies with the "Thousands Separator" settings and whether you enter a comma or point into the InputBox
. I had my "Thousands Separator" set to use a point .
because I'm working with .csv file exports so it was useful. Either will work but you have to change your Windows decimal symbol settings by going to:
Control Panel > Language > Change date, time, or number formats > Additional Settings > Decimal symbol
.
As for the multiplication part: The original InputBox
returns a string. Using Val()
converts the number string to a number and is the correct VBA script:
Private Sub CommandButton1_Click()
Dim myValue As Variant
myValue = Val(InputBox("Prompt", "Title"))
Range("C5").Value = myValue * Range("C3")
End Sub