+ Reply to Thread
Results 1 to 6 of 6

Thread: Select Range based on data in different column

  1. #1
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Select Range based on data in different column

    Hello all,

    How do I select a range in column G starting from the 3rd row till the word "total" occurs in column A?

  2. #2
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Select Range based on data in different column

    The word "total" is always the last value in column A, so perhaps starting from the bottom and offset it with 2 to select the corresponding cell in column C.
    Now I need to resize the selection to the top of column C3

    Sub test()
    
    Range("A1").End(xlDown).Offset(0, 2).Select
    
    End Sub
    But I can't get it done.
    Any suggestions?

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: Select Range based on data in different column

    This?
    Range("C3", Range("A" & Rows.Count).End(xlUp).Offset(, 2)).Select

  4. #4
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: Select Range based on data in different column

    You could use this to set the range for Column G based on the word "total" being in Column A
    Sub setRNG()
    Dim fCell As Range, lCell As Range, foundRange As Range
    Dim fAdd As String
    With Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
        Set lCell = .Cells(.Cells.Count)
    End With
    Set fCell = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Find(what:="total", after:=lCell)
    If Not fCell Is Nothing Then
        fAdd = fCell.Row
    Set foundRange = Range("G3:G" & fAdd)
    foundRange.Select
    Else
    MsgBox "Cannot find the word Total"
    End If
    End Sub
    Where foundRange is the range from G3 to Gx where x is the row number where Column A has the word "total"

    Edit - I did not see that total was always the last row in Column A - you would not need something as elaborate as above you would only have to find the last row number of column A
    Set foundRange = Range("G3:G" & Cells(Rows.Count, "A").End(xlUp).Row)
    Did not read your second post
    Last edited by smuzoen; 01-24-2012 at 07:33 AM.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated

  5. #5
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Select Range based on data in different column

    cells(3,3).resize(cells(rows.count,3).end(xlup).row-2)



  6. #6
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Select Range based on data in different column

    Thank you guys,
    I used StephenR's code, works fine

+ 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.2.0