Announcement

Collapse
No announcement yet.

select and group cells based on cell value

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • select and group cells based on cell value

    Im trying to get a vba code that will enable me to look at the last cell in a column, says its value is 10. Then highlight the preceding lines based on the cell value and group them

    H15=10

    Highlight rows H16: H25 and then group

    Is there a VBA code for this. Ive been looking on the web all weekend with no real luck

    Thanks

  • #2
    Re: select and group cells based on cell value

    see if this helps

    Code:
    Sub example()
    Set myrange = Sheets("sheet1").Range("H1", Range("H" & Rows.Count).End(xlUp))
    Set p = Sheets("sheet1").Cells(myrange(1, 1).Offset(myrange.Rows.Count - 1, 0).Row + 1, myrange(1, 1).Offset(myrange.Rows.Count - 1, 0).Column)
    Set r = Sheets("sheet1").Cells(myrange(1, 1).Offset(myrange.Rows.Count - 1, 0).Row + myrange(1, 1).Offset(myrange.Rows.Count - 1, 0).Value + 1, myrange(1, 1).Offset(myrange.Rows.Count - 1, 0).Column)
    myrange = p.Address & ":" & r.Address
    Range(myrange).Select
    End Sub

    Comment


    • #3
      Re: select and group cells based on cell value

      Thankyou so much. God I wish I had you skills.

      I just had to take out the value of 1 in Set r line of code and add in selection.rows.group as the last line and it works a treat.

      Comment

      Working...
      X