Consulting

Results 1 to 3 of 3

Thread: Solved: Hide range of column on sheet2 from sheet1

  1. #1
    VBAX Regular
    Joined
    Mar 2009
    Location
    Webster NY
    Posts
    16
    Location

    Solved: Hide range of column on sheet2 from sheet1

    I have code to hide a range of columns on an active sheet using a scrollbar but I would like to hide the same columns on an inactive sheet (Sheet2) without shifting focus from Sheet1. Here is the code that I’m using for the active sheet. For the life of me I have not been able to figure the code to do it on an inactive sheet. I'm still pretty new to VBA but I’m sure this must be achievable. Thanks for any help

    [vba]Private Sub ScrollBar1_Change()
    Dim left_column_range As Integer
    Dim right_column_range As Integer
    Dim cCount As Integer
    cCount = ActiveSheet.ScrollBar1.Value

    left_column_range = cCount
    right_column_range = left_column_range + 8

    Range(Cells(, left_column_range), Cells(1, right_column_range)).EntireColumn.Hidden = False
    Range(Cells(, left_column_range), Cells(1, right_column_range)).EntireColumn.AutoFit
    Range(Cells(1, 2), Cells(1, left_column_range)).EntireColumn.Hidden = True
    Range(Cells(1, right_column_range), Cells(1, 430)).EntireColumn.Hidden = True[/vba]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Get the address of each range from Sheet1 and apply it to Sheet2 like so
    [vba] Dim Rng As String
    Rng = Range(Cells(, left_column_range), Cells(1, right_column_range)).Address
    Sheets(1).Range(Rng).EntireColumn.Hidden = False
    Sheets(2).Range(Rng).EntireColumn.Hidden = False[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Mar 2009
    Location
    Webster NY
    Posts
    16
    Location

    Resolved

    Thanks mdmackillop that worked great

Posting Permissions

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