+ Reply to Thread
Results 1 to 3 of 3

case select and a range

  1. #1
    JT
    Guest

    case select and a range

    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

  2. #2
    SFatz
    Guest

    Re: case select and a range

    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?

    "JT" <anonymous@discussions.microsoft.com> wrote in message
    news:011e01c504aa$7e66e0b0$a501280a@phx.gbl...
    > 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




  3. #3
    Tom Ogilvy
    Guest

    Re: case select and a range

    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


    --
    Regards,
    Tom Ogilvy


    "JT" <anonymous@discussions.microsoft.com> wrote in message
    news:011e01c504aa$7e66e0b0$a501280a@phx.gbl...
    > 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




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1