Consulting

Results 1 to 7 of 7

Thread: Solved: Specifying last row range

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Solved: Specifying last row range

    I have this code to highlight cells with value <100k.

    [VBA]Sub Lessthan100k()

    Dim cll As Range, rng As Range
    Set rng = Range("I53:R" & Cells(Rows.Count, "I").End(xlUp).Row)
    For Each cll In rng

    If cll.Value < 100000# Then cll.Select

    With Selection.Font
    .Color = -16776961
    .TintAndShade = 0
    End With

    Next cll
    End Sub
    [/VBA]

    But my sheets are always going to be a different number of rows so instead of setting the range as I53:R, i need to me more general and set the range as:

    lastrow = .Cells(.Rows.Count, "I").End(xlUp).Row + 2
    .Cells(lastrow + 1, 9) to .Cells(lastrow + 1, 18)

    Any ideas on how to do this correctly to get a more general code to specify my range?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is this what you mean?


    [VBA]Sub Lessthan100k()

    Dim cll As Range, rng As Range
    With ActiveSheet

    Set rng = .Range("I53:R" & .Cells(.Rows.Count, "I").End(xlUp).Row + 3)
    For Each cll In rng

    If cll.Value < 100000# Then

    With cll.Font

    .Color = -16776961
    .TintAndShade = 0
    End With
    End If
    Next cll
    End With
    End Sub[/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Sheet for above post

    On the above post, here is the sheet I am working with. I am trying to define the range highlighted in green in terms of lastrow.
    Attached Files Attached Files

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Sub Lessthan100k()

    Dim cll As Range, rng As Range
    With ActiveSheet

    Set rng = .Range("I" & .Cells(.Rows.Count, "A").End(xlUp).Row + 3).Resize(3, 10)
    For Each cll In rng

    If cll.Value < 100000# Then

    With cll.Font

    .Color = -16776961
    .TintAndShade = 0
    End With
    End If
    Next cll
    End With
    End Sub
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    That works great, thank you!!!

  6. #6
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    How does the resize(3,10) work? I am trying to write a similar code and dont understand what that specifies?

    Thanks

  7. #7
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    I figured it out, I was just referencing the wrong thing:

    [VBA]Sub Macro5()
    '
    Dim cll As Range, rng As Range
    With ActiveSheet

    Set rng = .Range("H" & .Cells(.Rows.Count, "A").End(xlUp).Row + 3).Resize(3, 11)
    For Each cll In rng

    With cll.Interior

    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 5296274
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    Next cll
    End With

    End Sub
    [/VBA]

Posting Permissions

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