+ Reply to Thread
Results 1 to 5 of 5

Using variable for range address

  1. #1
    dr chuck
    Guest

    Using variable for range address



    If Range("h9").Value = "N" Then
    Selection.AutoFilter Field:=1, Criteria1:="+"
    End If

    I want to be able to replace "h9" with a variable that i can change
    frequently. (ie h9, j12,or whatever cell address i want to use).

    I have tried ....
    Dim Ant string
    Ant = "h9"
    If Range("Ant").Value = "N" Then
    Selection.AutoFilter Field:=1, Criteria1:="+"
    End If

    This however does not work. I am not sure of the proper syntax to achieve
    this goal.


    Thanks in advance--
    dr chuck

  2. #2

    Re: Using variable for range address

    take the quotes away from ANT - with quotes, you are referring to a
    named range ANT, without you are referring to the variable - so

    if range(ant).value etc


  3. #3
    Ardus Petus
    Guest

    Re: Using variable for range address

    Dim Ant as String
    Ant="H9"
    if range(Ant).value="N" then

    HTH
    --
    AP

    "dr chuck" <[email protected]> a écrit dans le message de
    news: [email protected]...
    >
    >
    > If Range("h9").Value = "N" Then
    > Selection.AutoFilter Field:=1, Criteria1:="+"
    > End If
    >
    > I want to be able to replace "h9" with a variable that i can change
    > frequently. (ie h9, j12,or whatever cell address i want to use).
    >
    > I have tried ....
    > Dim Ant string
    > Ant = "h9"
    > If Range("Ant").Value = "N" Then
    > Selection.AutoFilter Field:=1, Criteria1:="+"
    > End If
    >
    > This however does not work. I am not sure of the proper syntax to achieve
    > this goal.
    >
    >
    > Thanks in advance--
    > dr chuck




  4. #4
    Crowbar via OfficeKB.com
    Guest

    Re: Using variable for range address

    Remove the ""

    >Dim Ant string
    >Ant = "h9"
    > If Range(Ant).Value = "N" Then
    > Selection.AutoFilter Field:=1, Criteria1:="+"
    > End If


    [email protected]

    --
    Message posted via http://www.officekb.com

  5. #5
    dr chuck
    Guest

    Re: Using variable for range address

    thanks guys .. for the immediate help

    --
    dr chuck


    "Crowbar via OfficeKB.com" wrote:

    > Remove the ""
    >
    > >Dim Ant string
    > >Ant = "h9"
    > > If Range(Ant).Value = "N" Then
    > > Selection.AutoFilter Field:=1, Criteria1:="+"
    > > End If

    >
    > [email protected]
    >
    > --
    > Message posted via http://www.officekb.com
    >


+ 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