case select and a range

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

Instead of listing all of the valid values, I would like
to use a range name in a case select statement. Is this
possible. Following is the code I'm using without much
success. "VV" is the name of the range that contains the
values I want to check against.

Sub find_match()

Select Case cell

Case ("VV")
counter = counter + 0

Case Else

ActiveCell.Interior.ColorIndex = 6
counter = counter + 1

End Select

End Sub

Thanks for the help
 
You won't be able to use a Select statement, but you probably can use a For
Each, depending on what you're really trying to do.

Sub find_match()
Dim rngT as Cell
For Each rngT in Range("VV")
If cell.value = rngT.value Then
counter = counter + 0
Else
ActiveCell.Interior.Color = 6
counter = counter + 1
End If
Next rngT
End Sub

Hope this helps
By the way, why bother incrementing the counter by 0?
 
Sub find_match()
counter = 0
For Each cell In Range("A1:A10")
Select Case True
Case Not IsError(Application.Match(cell, Range("VV"), 0))
counter = counter + 0
Case Else
ActiveCell.Interior.ColorIndex = 6
counter = counter + 1
End Select
Next
Range("B1") = counter
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to hide password? 1
Select Case code error 8
Loop without Do 2
Simple IF give me nothing? 2
Do Until or For Loop 3
Automatically selecting active chart 4
help with a piece of code 5
Run Time Error 1004 7

Back
Top