Select first row of an Excel table

Raddle

New Member
Joined
Oct 24, 2023
Messages
41
Office Version
  1. 2016
Hi

I need to turn on freeze panes from the first row of the table on each sheet.
This should allow the user to scroll but keep the headers.

I can select the table but the .databodyrange argument is not playing ball for me.

Any hints here? I know there has been a lot on this and I have looked but can't quite get there

Sub Acnt_FreezePanes() 'freeze panes for each table
Dim tbl As ListObject
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets
ws.Activate ' I have to do this or it does not work at all - no sure why
With ws
For Each tbl In ws.ListObjects
If tbl.name <> "Tbl_FilePath" Then
tbl.Range.Select ' this is where I really want to use databodyrange but I can't fit it in ...
ActiveWindow.FreezePanes = True
Debug.Print ws.name

End If
Next tbl
End With

Next ws
End Sub


Many thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try:
VBA Code:
Sub Acnt_FreezePanes() 'freeze panes for each table
Dim tbl As ListObject
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets
ws.Activate ' I have to do this or it does not work at all - no sure why
With ws
    For Each tbl In ws.ListObjects
        If tbl.Name <> "Tbl_FilePath" Then
        tbl.DataBodyRange.Rows(1).Select 
        ActiveWindow.FreezePanes = True
        Debug.Print ws.Name
    End If
    Next tbl
End With
Next ws
End Sub
 
Upvote 0
Solution
! yep - that has sorted it.

Pity about databodyrange .. that seemed a nice approach.

Thank you so much!!!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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