Consulting

Results 1 to 5 of 5

Thread: Scroll to column via Combobox

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Scroll to column via Combobox

    I have a spreadsheet with multiple column headers.
    I have Column A with a Combobox that has a list of all headers.
    I also have frozen panels so Column A and Row 1 always are showing.

    I would like for when I select a header name from the combobox for the column next to A move to that column.

    So If I select Desktops from the Combobox and Desktops header is in Column H then I will see Column A then H next to it.

    I know you can use something like this
    [VBA]ActiveWindow.SmallScroll ToRight:=5[/VBA]

    But the problem with that is it moves over from where it is at that moment not from Column B.

    Any suggestions?

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    [VBA]Private Sub ComboBox1_Change()
    Worksheets(1).Cells(1, Worksheets(1).ComboBox1.ListIndex + 2).Select
    End Sub
    [/VBA]

    David


  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Thanks Tinbendr, but that's not what Im trying to accomplish.
    I would like for the columns to move mainly for viewing purposes, I don't want to select the column.

    So selected option in combobox will be right next to column A, but I will still remain in ComboBox

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    OK, I see.

    Try this.

    [VBA]Private Sub ComboBox1_Change()
    ActiveWindow.SmallScroll toleft:=7
    ActiveWindow.SmallScroll ToRight:=Sheet2.ComboBox1.ListIndex

    End Sub
    [/VBA]
    First line returns the column to the far left. (There's probably a better way to do this, but i couldn't find it.)
    Second line moves the scroll to the right equal to the index in the combobox.

    Adjust as required.

    David


  5. #5
    good to learn it..

Posting Permissions

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