Help!
i need to make an input box using coding that asks for two numbers and subtracts the first num from the second one
then, i need a msgbox that shows the answer
stop project until i get better
wait
use a totally different macro
don't do it ever again
Help!
i need to make an input box using coding that asks for two numbers and subtracts the first num from the second one
then, i need a msgbox that shows the answer
![]()
Dim numbers As String Dim vecNumbers As Variant numbers = InputBox("Supply two numbers comma separated") If numbers <> "" Then vecNumbers = Split(numbers, ",") MsgBox vecNumbers(1) - vecNumbers(0) End If
How about:
![]()
Sub marine() With Application N1 = .InputBox(prompt:="Enter first number", Type:=1) N2 = .InputBox(prompt:="Enter second number", Type:=1) MsgBox N2 - N1 End With End Sub
Gary's Student
jakobshavn, u didn't define N1 or N2
Bob, there is an error when i run it ( compile error)
You are correct! The macro should run without the definitions.
is N1 an integer,string etc.?
![]()
Jakob, u didn't define N1 or N2 so there is an error
Dim them as Variants
When you respond, touch Go Advanced at the bottom and use the paperclip.
I've redone Jakobshavn's code a bitThere should be no errors now with Option Explicit on.![]()
Sub marine() Dim N1 As Double, N2 As Double Dim tot As Double With Application N1 = .InputBox(prompt:="Enter first number", Type:=1) N2 = .InputBox(prompt:="Enter second number", Type:=1) tot = N1 - N2 MsgBox tot End With End Sub
---------- Post added at 02:41 PM ---------- Previous post was at 02:39 PM ----------
I just ran Bob's code and didn't receive any errors. What was the description of the error thrown?
Last edited by Mordred; 08-22-2012 at 04:45 PM.
If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.
---Keep on Coding in the Free World---
Use the marine macro not the inputbox macro
---------- Post added at 04:26 PM ---------- Previous post was at 04:25 PM ----------
N1 and N2 weren't defined yet
---------- Post added at 04:27 PM ---------- Previous post was at 04:26 PM ----------
Don't change the project unless u can improve it
I can't say that I understand your post 13! Did you try the amended code that I did? With Bob's, did you copy and paste it into your workbook because the code you have in there is not the same?!?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks