check out select case in VBA help
Also it may be an idea to name the (multiarea) ranges
your going to check.
then again.. following would work
Sub InsertCheck()
Dim rCol As Range
Dim rRow As Range
Dim n As Integer
Set rCol = Range("A:A,F:F,H:H,J:J,L:L")
Set rRow = Range("7:7,12:12,17:17,22:22,27:27,32:32")
n = -1
If Not Intersect(ActiveCell, rCol) Is Nothing Then
For n = 0 To 4
If Not Intersect(ActiveCell, rRow.Offset(n)) Is Nothing Then
Exit For
End If
Next
End If
Select Case n
Case 0: ActiveCell = "Craig"
Case 1: ActiveCell = "Doug"
Case 2: ActiveCell = "Mike"
Case 3: ActiveCell = "Pete"
Case 4: ActiveCell = "Jane"
Case Else: Beep
End Select
End Sub
--
keepITcool
|
www.XLsupport.com | keepITcool chello nl | amsterdam
Craig wrote :
Hi there,
Within my cmdInsert code: when I click the cmdInsert i wish the code
to check to see if the activecell is one of 30 predifined cell
address's. The method I know would creat a huge if( and(. I wonder
if there is a easier way.
Example:
If activecell.address = D7 or F7 or H7 or J7 or L7 or D12 or F12 or
H12 or J12 or L12 or D17 or F17 or H17 or J17 or L17 or D22 or F22 or
H22 or J22 or L22 or D27 or F27 or H27 or J27 or L27 or D32 or F32 or
H32 or J32 or L32 Then Activecell.value = "Craig" elseif
activecell.address = D8 or F8 or H8 or J8 or..... then
Activecell.value = "Doug" elseif activecell.address = D9 or F9 or H9
or J9 or..... then Activecell.value = "Michael" Is there an easier
way to test 7 sets of 30 cells ?
Thanks Craig