Dynamic Table Hide Rows

CJG19

New Member
Joined
Jul 12, 2021
Messages
40
Office Version
  1. 2010
Platform
  1. Windows
Good Morning!

I wonder if someone can help 🙏

I am trying to select all rows in a table not including the header/title row and the last row. The data in my table underneath the header/title row starts in cell A4 for context. I have the below code which I have been working on, but it seems to be selecting to row 46, but my last row (which I still want showing is currently row 8). This is a table that will be added to, so the code needs to find the last row, go up one row and select from there to the header/title row. (There is nothing at all below row 8, I have performed a 'Clear All' just in case).

VBA Code:
Dim sht As Worksheet
Dim LR As Long
Dim Lc As Long
Dim FirstCell As Range

    Set sht = Worksheets("Sheet 4")
    Set FirstCell = Range("A4")
    LR = FirstCell.SpecialCells(xlCellTypeLastCell).Row
    Lc = FirstCell.SpecialCells(xlCellTypeLastCell).Column
    sht.Range(FirstCell, sht.Cells(LR - 1, Lc)).Select
    Selection.EntireRow.Hidden = True

Any help would be very much appreciated

Kind Regards,

CJG19
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Please try this

VBA Code:
Sub SelectMidRange()

  Dim sht As Worksheet
  Dim LR As Long
  Dim Lc As Long
  Dim FirstCell As Range
  Dim LastCell As Range
  

  Set sht = Worksheets("Sheet4")
  Set FirstCell = sht.Range("A4")
  Set LastCell = sht.Cells(sht.Cells.Rows.Count, 1).End(xlUp)
  sht.Range(FirstCell.Offset(1, 0), LastCell.Offset(-1, 0)).EntireRow.Select
  Selection.EntireRow.Hidden = True
  
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top