Consulting

Results 1 to 5 of 5

Thread: Solved: MsgBox to ensure proper values are used

  1. #1

    Solved: MsgBox to ensure proper values are used

    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

  2. #2
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    [VBA]
    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[/VBA]

  3. #3
    Thank you very much mbarron.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    To "correct" a wrong entry, something like this using the MOD operator
    [vba]
    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

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •