Link to home
Start Free TrialLog in
Avatar of sandramac
sandramac

asked on

Command Button

I need to find a way to active a message box based on several variables

First is ActiveCell.Offset (0,-31) value is between 0255-0258 or 0555-0559 or 0855-0859, or 1155-1159 or 1455-1459 or 1755-1759, or 2055-2059, or 2355-2359.  And if ActiveCell.Offset (0,-35) is blank.  Then activate Message Box "Please enter the data"
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hi sandramac,

Better ask al these excel questions in the Office section but here we go

Sub CheckInput()

Rem declare variables
Dim intCheckVal As Integer
Dim i As Integer, j As Integer

Rem check if cell to check is numeric else leave sub
If Not IsNumeric(ActiveCell.Offset(0, -1)) Then Exit Sub
intCheckVal = ActiveCell.Offset(0, -1)
Rem set start values
i = 255
j = 259
Rem loop till the highest range to check
While Not i > 2359
  If Not (i < intCheckVal And intCheckVal < j) Then
    i = i + 300
    j = j + 300
  Else
Rem exit because the value was found in one of the ranges
    Exit Sub
  End If
Wend
Rem show the box
MsgBox "Please enter the data"
End Sub

this proc assumes you're using integer values for the ranges

HTH:O)Bruintje
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of twalgrave
twalgrave

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to aikimark
Please leave any comments here within the
next seven days.
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange