VBA help needed with Excel input box and calculation please

Attleborough

Registered user
Joined
Jan 22, 2006
Messages
470
Reaction score
0
Location
Just off the A11
I need to produce an input box in excel in which users enter a value and on clicking OK the value is multiplied by say .15 and the result entered into a cell say A5.

I can do the button but can anyone help me with the code please?
 
If the input box was for example A3 then this should work

Range("A5").Value = Range("A3").Value * 0.15


Save as a macro then assign the macro to the button
Is this what you mean ?...

Or, would it not be easier to just assign a formula to cell A5
=a3*0.15

as soon as you tabbed off, the value gets updated, no pressing of buttons required.


(hhmm, thought about this a little more).

Of course the other way is to create an input box that appears, enter the number and the result displayed and to do that your macro code would look like...

Sub NumericDataType()

Dim lNum As Long

On Error Resume Next

Application.DisplayAlerts = False

lNum = Application.InputBox _
(Prompt:="Please enter a number", _
Title:="Enter a Number", Type:=1)

On Error GoTo 0

Application.DisplayAlerts = True

lNum = lNum * 0.15
Range("A5").Value = lNum

End Sub
 
Shouldn't it read 'lNum = Application/InputBox '

Don't answer the above as I have not got a clue what I am talking about, seriously this is a foreign language to me and it means nothing.

Does anyone here know what oil I should put in my 1200?
 
Thanks for the replies. I don't seem to be able to get the suggestion to run in Excel 2003.

I do need the code to be attached to a button. If there are any other suggestions they will gratefully be received.

Thanks

A.
 
Error checking ignored...

Dim inputNumberAsString As String
Dim inputValue As Double
Dim calcValue As Double

inputNumberAsString = InputBox("Enter value", "A value")

inputValue = CDbl(inputNumberAsString)

calcValue = inputValue * 0.15

ActiveWorkbook.Worksheets(1).Range("A5") = calcValue
 
Thanks Clive for your solution which I've got working for me and also to TaffyMc & Daffy who took the trouble to offer help.

Much obliged.

A.
 


Back
Top Bottom