PDA

View Full Version : Solved: MsgBox to ensure proper values are used



jolivanes
11-24-2009, 08:01 PM
Following is part of code I am using



Set myrange = Range("H2", Range("H" & 3 + 360 / Range("G4").Value))


I would like to have a MsgBox pop up when 360 is divided by G4 and the result is anything else than a whole number, a number with 0.25, 0.5 or 0.75. That would be a MsgBox with a warning to use a different number and then Exit Sub.

I tried with MOD but that does not work at all (for me)

Could someone help me with this.

Thanks in advance

Regards

John

mbarron
11-24-2009, 08:39 PM
If Int(360/Range("G4").Value)<>360/Range("G4").Value Then
MsgBox "Please enter a different number"
Exit Sub
Else
Set myrange = Range("H2", Range("H" & 3 + 360 / Range("G4").Value))
End If

jolivanes
11-24-2009, 09:11 PM
Thank you very much mbarron.

mdmackillop
11-25-2009, 06:38 AM
To "correct" a wrong entry, something like this using the MOD operator

Dim MyRange As Range, Rw As Long
Rw = 3 + 360 / (Range("G4") - (360 Mod Range("G4")))
Set MyRange = Range("H2", Range("H" & Rw))
MyRange.Select

jolivanes
11-25-2009, 02:13 PM
mdmackillop.

Thank you very much for your reply.
I have to chew on that code for a bit because when I tried it, the figures went well beyond 360. The filling in numbers ought to go to the first number > 360.

Thanks again.

John