Scroll to Table Column by Referencing Table Header in Lieu of Table Column Number

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
568
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I'm trying to get my code below right to allow me to scroll over to a table column on my worksheet. I can easily enter the column number (13) and it will do just that, but trying to keep this code dynamic so that I can insert additional columns down the road and not have to worry about re-writing the code for column number references. Not that I have the first two rows and first 5 columns set as frozen panes. Any help would be greatly appreciated.


Thanks, SS



VBA Code:
Sub Scroll_to_PMT_COL()
'
' Scroll to Payment Column Macro
'
    Dim wBook As Workbook
    Dim wSheet As Worksheet
    Dim tb As ListObject

    Set wBook = ThisWorkbook
    Set wSheet = wBook.Sheets("Jobs")
    Set tb = wSheet.ListObjects("G2JobList")

    Worksheets("Jobs").Activate

        ActiveWindow.ScrollColumn = tb.ListColumns("Down" & Chr(10) & "Payment").Select

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Got it...

VBA Code:
Sub Scroll_to_PMT_COL()
'
' Scroll to Payment Column Macro
'
    Dim ws As Worksheet
    Dim sTable As String
    Dim loTable As ListObject
    Dim lc As ListColumn
    
    sTable = "G2JobList"
    Set ws = ActiveSheet
    Set loTable = ws.ListObjects(sTable)
    Set lc = loTable.ListColumns("Down" & Chr(10) & "Payment")
    
    ActiveWindow.ScrollColumn = lc.Range.Column


End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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