PDA

View Full Version : Solved: Hide range of column on sheet2 from sheet1



Jeff1959
03-15-2009, 12:53 PM
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

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

mdmackillop
03-15-2009, 01:11 PM
Get the address of each range from Sheet1 and apply it to Sheet2 like so
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

Jeff1959
03-15-2009, 04:31 PM
Thanks mdmackillop that worked great :thumb