+ Reply to Thread
Results 1 to 7 of 7

determine which column has a value

  1. #1

    determine which column has a value

    I am using =MATCH("Totals",B1:AZ1,0) to tell me which column 'totals'
    is in. However, the result is an integer and I would like to use this
    column in a range("x:x+3") statement.

    How can I calculate the above and be able to use the results in a
    range() statement?

    Ultimately, I want to be able to do this:
    If Not Intersect(target, Range("B:J")) Is Nothing Then target.Offset(0,
    11).Select
    with a variable range of columns.

    Thanks.


  2. #2
    JE McGimpsey
    Guest

    Re: determine which column has a value

    Perhaps

    Dim rTotal As Range
    Set rTotal = Rows(1).Find( _
    What:="Totals", _
    LookIn:=xlValues, _
    LookAt:=xlWhole, _
    MatchCase:=False)
    If Not rTotal Is Nothing Then _
    If Target.Column >= 2 And Target.Column <= rTotal.Column Then _
    Target.Offset(0, 11).Select

    In article <[email protected]>,
    [email protected] wrote:

    > I am using =MATCH("Totals",B1:AZ1,0) to tell me which column 'totals'
    > is in. However, the result is an integer and I would like to use this
    > column in a range("x:x+3") statement.
    >
    > How can I calculate the above and be able to use the results in a
    > range() statement?
    >
    > Ultimately, I want to be able to do this:
    > If Not Intersect(target, Range("B:J")) Is Nothing Then target.Offset(0,
    > 11).Select
    > with a variable range of columns.
    >
    > Thanks.


  3. #3

    Re: determine which column has a value

    Looks good except Target.Offset(0, 11).Select because the 11 is no
    longer static. Instead 11 should be the distance between column b and
    the targetcolumn, ie if a doubleclick is in the first column of the
    range, the select should be to the column after 'totals'.


  4. #4
    George Nicholson
    Guest

    Re: determine which column has a value

    You can probably use the integer:
    Intersect(target, range(columns(2),columns(x)))

    There may be a more elegant/concise way to express that, but if so, it
    escapes me at the moment.

    HTH,
    --
    George Nicholson

    Remove 'Junk' from return address.


    <[email protected]> wrote in message
    news:[email protected]...
    >I am using =MATCH("Totals",B1:AZ1,0) to tell me which column 'totals'
    > is in. However, the result is an integer and I would like to use this
    > column in a range("x:x+3") statement.
    >
    > How can I calculate the above and be able to use the results in a
    > range() statement?
    >
    > Ultimately, I want to be able to do this:
    > If Not Intersect(target, Range("B:J")) Is Nothing Then target.Offset(0,
    > 11).Select
    > with a variable range of columns.
    >
    > Thanks.
    >




  5. #5

    Re: determine which column has a value

    How can express a range that contains all the columns from
    rtotals.column+1 to last used column?


  6. #6
    JE McGimpsey
    Guest

    Re: determine which column has a value

    If I understand you correctly, try

    Target.Offset(0, rTotal.Column - 1).Select


    In article <[email protected]>,
    [email protected] wrote:

    > Looks good except Target.Offset(0, 11).Select because the 11 is no
    > longer static. Instead 11 should be the distance between column b and
    > the targetcolumn, ie if a doubleclick is in the first column of the
    > range, the select should be to the column after 'totals'.


  7. #7
    JE McGimpsey
    Guest

    Re: determine which column has a value

    One way:

    With rTotals.Parent
    Set rTest = Intersect(Range(rTotals(1, 2), .Cells( _
    .Rows.Count, .Columns.Count)), .UsedRange).EntireColumn
    End With

    Note, this assumes that there's at least one column to the right of
    rTotals in .UsedRange.



    In article <[email protected]>,
    [email protected] wrote:

    > How can express a range that contains all the columns from
    > rtotals.column+1 to last used column?


+ 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