Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default Checking if Target is within different ranges

I would like to do an if/elseif statement or case statement to determine if the cell the user entered data in is in 7 different ranges. Depending on which range it is in I would like to check the value of the cell with the value of another cell(different cell for each range) and based on that check display a msgbox. This is what I have so far. I just need to know how to change this so that the cell that the user entered data into is compared to 7 different ranges. The ranges are C13:C15, E13:E15, G13:G15, I13:I15, K13:K15, M13:M15, O13:O15. Right now my code only checks to see if the target is in the C13:C15 range. I think a case statement would be better, but I'm not sure. In the case statement, for each case I will be comparing the cell with a different cell. Thanks. Matt

If cbExempt.Value = True Then
If Intersect(Target, [C13:C15]) Is Nothing Then
Exit Sub
End If
With Target
If .Value = "AL" And Not IsEmpty(Range("D10")) Then
MsgBox ("Please enter ADDHR = number of hours worked and reason on the overtime explanation at the bottom.")
ElseIf .Value = "HDAY" And Not IsEmpty(Range("D10")) Then
MsgBox ("Please enter HOLWK = number of hours worked and reason on the overtime explanation at the bottom.")
End If
End With
End If


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checking if Target is within different ranges

Dim rng as Range, rng1 as Range, rng2 as Range
Dim i as Long, bIntersect as Boolean
' enter your 7 cells to check against.
bIntersect = False
varr = vArray("D10","M12", . . . ,"Z21")
set rng = Range("C13")
for i = 1 to 7
set rng1 = rng.Offset(0, (i - 1) * 2).Resize(3, 1)
if not intersect(target, rng1) is nothing then
set rng2 = Range(varr(i))
' perform your checks
bIntersect = True
exit for
Next
' if you have processing below this, then you
' can exit if no intersect was made
' otherwise you don't need to check.
if bIntersect = False then exit sub

End if

--
Regards,
Tom Ogilvy

"Matt" wrote in message
...
I would like to do an if/elseif statement or case statement to determine

if the cell the user entered data in is in 7 different ranges. Depending on
which range it is in I would like to check the value of the cell with the
value of another cell(different cell for each range) and based on that check
display a msgbox. This is what I have so far. I just need to know how to
change this so that the cell that the user entered data into is compared to
7 different ranges. The ranges are C13:C15, E13:E15, G13:G15, I13:I15,
K13:K15, M13:M15, O13:O15. Right now my code only checks to see if the
target is in the C13:C15 range. I think a case statement would be better,
but I'm not sure. In the case statement, for each case I will be comparing
the cell with a different cell. Thanks. Matt

If cbExempt.Value = True Then
If Intersect(Target, [C13:C15]) Is Nothing Then
Exit Sub
End If
With Target
If .Value = "AL" And Not IsEmpty(Range("D10")) Then
MsgBox ("Please enter ADDHR = number of hours worked and

reason on the overtime explanation at the bottom.")
ElseIf .Value = "HDAY" And Not IsEmpty(Range("D10")) Then
MsgBox ("Please enter HOLWK = number of hours worked and r

eason on the overtime explanation at the bottom.")
End If
End With
End If




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Error Checking doesn't work on column ranges? genegal New Users to Excel 1 January 25th 10 05:19 AM
Spell Checking with checking cell notes jfitzpat Excel Discussion (Misc queries) 0 August 8th 07 10:26 PM
Target cell reference moves when target is cut and pasted Illya Teideman Excel Discussion (Misc queries) 5 May 31st 07 11:34 AM
How find if target is object in Worksheet_Change (ByVal Target As.. ?) Gunnar Johansson Excel Programming 3 July 1st 04 09:25 PM
named ranges - changing ranges with month selected gr8guy Excel Programming 2 May 28th 04 04:50 AM


All times are GMT +1. The time now is 10:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"