I am new just now taking classes on excel and using VB and VBA. Anyways I am having difficulties doing a code. Right now I have:
[CODE=vb]Option Explicit
Public Sub Problem4()
Dim Var1 As Long, Var2 As Long, Var3 As Long
'Input 3 numbers from user
Var1 = InputBox("Enter the first integer :", "First")
Var2 = InputBox("Enter the second integer :", "Second")
Var3 = InputBox("Enter the third integer :", "Third")
Range("a1").Val ue = "First number ="
Range("a2").Val ue = "Second number ="
Range("a3").Val ue = "Third number ="
Range("b1").Val ue = Var1
Range("b2").Val ue = Var2
Range("b3").Val ue = Var3
'Find the Largest Number
If Var1 > Var2 And Var1 > Var3 Then
Range("a4").Val ue = "The largest number is " & Var1
ElseIf Var2 > Var1 And Var2 > Var3 Then
Range("a4").Val ue = "The largest number is " & Var2
ElseIf Var3 > Var1 And Var3 > Var2 Then
Range("a4").Val ue = "The largest number is " & Var3
End If
'Find the Smallest Number
If Var1 < Var2 And Var1 < Var3 Then
Range("a5").Val ue = "The smallest number is " & Var1
ElseIf Var2 < Var1 And Var2 < Var3 Then
Range("a5").Val ue = "The smallest number is " & Var2
ElseIf Var3 < Var1 And Var3 < Var2 Then
Range("a5").Val ue = "The smallest number is " & Var3
End If
If Var1 Mod 2 = 0 Then
Range("a6").Val ue = "This is an even number" & Var1
Else = "This is an odd number" & Var1
End If
Columns("a").En tireColumn.Auto Fit
End Sub[/CODE]
I am fine up to the point of the if Var1 Mod 2=0 part. I have to display in excel after the calculation if the number is odd or even and I cant seem to get the right code to work. I have to do this for all three variables. Any help with writing the code would be appreciated. If you take out the if var1 and run the macro then everything works out fine. So all i need is the even/odd help.
[CODE=vb]Option Explicit
Public Sub Problem4()
Dim Var1 As Long, Var2 As Long, Var3 As Long
'Input 3 numbers from user
Var1 = InputBox("Enter the first integer :", "First")
Var2 = InputBox("Enter the second integer :", "Second")
Var3 = InputBox("Enter the third integer :", "Third")
Range("a1").Val ue = "First number ="
Range("a2").Val ue = "Second number ="
Range("a3").Val ue = "Third number ="
Range("b1").Val ue = Var1
Range("b2").Val ue = Var2
Range("b3").Val ue = Var3
'Find the Largest Number
If Var1 > Var2 And Var1 > Var3 Then
Range("a4").Val ue = "The largest number is " & Var1
ElseIf Var2 > Var1 And Var2 > Var3 Then
Range("a4").Val ue = "The largest number is " & Var2
ElseIf Var3 > Var1 And Var3 > Var2 Then
Range("a4").Val ue = "The largest number is " & Var3
End If
'Find the Smallest Number
If Var1 < Var2 And Var1 < Var3 Then
Range("a5").Val ue = "The smallest number is " & Var1
ElseIf Var2 < Var1 And Var2 < Var3 Then
Range("a5").Val ue = "The smallest number is " & Var2
ElseIf Var3 < Var1 And Var3 < Var2 Then
Range("a5").Val ue = "The smallest number is " & Var3
End If
If Var1 Mod 2 = 0 Then
Range("a6").Val ue = "This is an even number" & Var1
Else = "This is an odd number" & Var1
End If
Columns("a").En tireColumn.Auto Fit
End Sub[/CODE]
I am fine up to the point of the if Var1 Mod 2=0 part. I have to display in excel after the calculation if the number is odd or even and I cant seem to get the right code to work. I have to do this for all three variables. Any help with writing the code would be appreciated. If you take out the if var1 and run the macro then everything works out fine. So all i need is the even/odd help.
Comment