qpham26
02-12-2013, 12:43 PM
Hi guys, I am trying to do a simple program that tell if a number is divisible by 3 or 5
so if the number can only be divisible by 3 or 5 then it will return a msgbox saying " only divisible by ..."
if the number can divisble by both then msgbox "Divisible by 3 and 5"
if the number cannot divisble by both then msgbox "not Divisible by 3 and 5"
I was able to do this using if-else-then structure. But I have no idea how to use select case to do this.
Please help. Thanks a lot.
This is my work using if-else
Sub problem3()
Dim a As Double, b As Double, c As Double
Sheets("sheet3").Select
Range("b2").Select
a = ActiveCell.Value
b = a Mod 3
c = a Mod 5
If (b = 0 And c = 0) Then
MsgBox "Divisible by 3 and 5"
ElseIf (b = 0 And c <> 0) Then
MsgBox "Only divisible by 3"
ElseIf (c = 0 And b <> 0) Then
MsgBox "Only divisible by 5"
ElseIf (c <> 0 And b <> 0) Then
MsgBox "Not divisible by 3 and 5"
End If
End Sub
so if the number can only be divisible by 3 or 5 then it will return a msgbox saying " only divisible by ..."
if the number can divisble by both then msgbox "Divisible by 3 and 5"
if the number cannot divisble by both then msgbox "not Divisible by 3 and 5"
I was able to do this using if-else-then structure. But I have no idea how to use select case to do this.
Please help. Thanks a lot.
This is my work using if-else
Sub problem3()
Dim a As Double, b As Double, c As Double
Sheets("sheet3").Select
Range("b2").Select
a = ActiveCell.Value
b = a Mod 3
c = a Mod 5
If (b = 0 And c = 0) Then
MsgBox "Divisible by 3 and 5"
ElseIf (b = 0 And c <> 0) Then
MsgBox "Only divisible by 3"
ElseIf (c = 0 And b <> 0) Then
MsgBox "Only divisible by 5"
ElseIf (c <> 0 And b <> 0) Then
MsgBox "Not divisible by 3 and 5"
End If
End Sub