Consulting

Results 1 to 7 of 7

Thread: Solved: Select Range of all rows

  1. #1
    VBAX Regular
    Joined
    Jan 2007
    Posts
    28
    Location

    Solved: Select Range of all rows

    In the following code, I want to select a range from H2 to the last row of my sheet. The 62 is not constant. I need the last row to be determined by data in column b as h has no data.



    Range("H2:H62").Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
    Formula1:="0.75", Formula2:="0.97"
    Selection.FormatConditions(1).Interior.ColorIndex = 44
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="0.9621"
    Selection.FormatConditions(2).Interior.ColorIndex = 3

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

  3. #3
    VBAX Regular
    Joined
    Jan 2007
    Posts
    28
    Location
    This doesn't really help. I need more than just finding the last row. I need to use the last row number to select my range.

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    How about this:

    Selects a Column or Row of Cells in a Used Range

    [vba]
    Sub SelectColumn()
    Dim UpBound As Range
    Dim LowBound As Range
    If ActiveCell.Row > 1 Then
    If IsEmpty(ActiveCell.Offset(-1, 0)) Then
    Set UpBound = ActiveCell
    Else
    Set UpBound = ActiveCell.End(xlUp)
    End If
    Else
    Set UpBound = ActiveCellEnd If
    If ActiveCell.Row < Rows.Count Then
    If IsEmpty(ActiveCell.Offset(1, 0)) Then
    Set LowBound = ActiveCell Else
    Set LowBound = ActiveCell.End(xlDown)
    End If
    Else
    Set LowBound = ActiveCell
    End If
    Range(UpBound, LowBound).Select
    Set UpBound = Nothing
    Set LowBound = Nothing
    End Sub[/vba]

  5. #5
    VBAX Regular
    Joined
    Jan 2007
    Posts
    28
    Location
    This doesnt work. Pulls up debugger.

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    what does debugger say?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    I see it. Typing too fast. Try this:

    Chage this:

    [vba]Set UpBound = ActiveCellEnd If [/vba]

    to this:

    [vba]Set UpBound = ActiveCellEnd [/vba]

    Unmatched If

Posting Permissions

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