By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 429,373 Members | 1,792 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,373 IT Pros & Developers. It's quick & easy.

# Odd, Even

 P: 6 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: Expand|Select|Wrap|Line Numbers 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").Value = "First number ="         Range("a2").Value = "Second number ="         Range("a3").Value = "Third number ="         Range("b1").Value = Var1         Range("b2").Value = Var2         Range("b3").Value = Var3         'Find the Largest Number         If Var1 > Var2 And Var1 > Var3 Then             Range("a4").Value = "The largest number is " & Var1         ElseIf Var2 > Var1 And Var2 > Var3 Then             Range("a4").Value = "The largest number is " & Var2         ElseIf Var3 > Var1 And Var3 > Var2 Then             Range("a4").Value = "The largest number is " & Var3         End If         'Find the Smallest Number         If Var1 < Var2 And Var1 < Var3 Then             Range("a5").Value = "The smallest number is " & Var1         ElseIf Var2 < Var1 And Var2 < Var3 Then             Range("a5").Value = "The smallest number is " & Var2         ElseIf Var3 < Var1 And Var3 < Var2 Then             Range("a5").Value = "The smallest number is " & Var3         End If         If Var1 Mod 2 = 0 Then             Range("a6").Value = "This is an even number" & Var1         Else = "This is an odd number" & Var1            End If             Columns("a").EntireColumn.AutoFit End Sub 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. Sep 5 '07 #1
Share this Question
5 Replies

 P: 21 Expand|Select|Wrap|Line Numbers    Else = "This is an odd number" & Var1   The code fragment I have highlighted is where I think the problem is.... is this a school project, if so then I cannot really help you any more than to point you in the right direction :-) Sep 5 '07 #2

 Expert 100+ P: 1,445 Hi, Change it to : Expand|Select|Wrap|Line Numbers If Var1 Mod 2 = 0 Then      Range("a6").Value = "This is an even number" & Var1 Else       Range("a6").Value = "This is an odd number" & Var1 End If     REgards Veena Sep 5 '07 #3

 P: 21 Hi, Change it to : Expand|Select|Wrap|Line Numbers If Var1 Mod 2 = 0 Then      Range("a6").Value = "This is an even number" & Var1 Else       Range("a6").Value = "This is an odd number" & Var1 End If     REgards Veena I wasn't going to tell him exactly that as it is a homework task... but yes, that is what I had spotted. Sep 5 '07 #4

 Expert 5K+ P: 8,434 I wasn't going to tell him exactly that as it is a homework task... but yes, that is what I had spotted. You can find the homework/coursework policy here. I recommend everyone familiarise themselves with it. But what it really boils down to is this:We won't do your homework for you ("you" being the student). But if you are making a real effort and run into difficulties, we don't mind helping you to understand the way forward. After all, if you're really stuck you need to ask someone.Personally I'm satisfied that coreyover4 has done most of the work, though I also would have tried to prod him/her in the right direction rather than providing a ready-made answer. Sep 6 '07 #5

 P: 6 Thanks for the help. I didnt want the whole answer, I just wanted to get pointed in the right direction on where my code was wrong and how to fix it. Thanks and I appreciate the help. Sep 7 '07 #6

### Post your reply

Sign in to post your reply or Sign up for a free account. 