Hello!
I've got an excel app which gives the user the ability to hide or unhide multiple columns in a 2 dimension data table. Every 3rd column is hidden or unhidden for 75 column occurrences.
I'm using the code below for now, BUT IT TAKES FOREVER!
I think the key is to select multiple columns first and then hide or unhide the selection. The problem is, I can do it manually, but the code captured by the macro recorder doesn't work BECAUSE THERE ARE MERGED CELLS ACROSS THE COLUMNS.
Assume some row has the following cells merged.
A,B,C D,E,F G,H,I J,K,L M,N,O
and I want to hide a column in each merged range.
Here's what the recorder captured:
Range("B:B,E:E,H:H,K:K,N:N".Select
Range("N1".Activate
Selection.EntireColumn.Hidden = True (or FALSE)
This doesn't work when placed in a macro. It selects AND HIDES ALL COUMNS IN THE MERGED RANGE.
I APPRECIATE ANY HELP!!!!!
Thanks!
TMKTECH
--------------- Current Code ------------------
Sub Hide_Show_Cols(ByVal margin_chg As Boolean, ByVal amt_chg As Boolean, ByVal cap_chg As Boolean):
margin_col = [Col1_Margin].Column 'set initial columns
amt_col = [Col1_Amt].Column
cap_col = [Col1_Cap].Column
For c = 1 To 75
If margin_chg Then
Columns(margin_col).Hidden = _
IIf([Show_Margin] = True, False, True)
End If
If amt_chg Then
Columns(amt_col).Hidden = _
IIf([Show_Amt] = True, False, True)
End If
If cap_chg Then
Columns(cap_col).Hidden = _
IIf([Show_Cap] = True, False, True)
End If
margin_col = margin_col + 3 'set up starting columns
amt_col = amt_col + 3
cap_col = cap_col + 3
Next
End Sub
I've got an excel app which gives the user the ability to hide or unhide multiple columns in a 2 dimension data table. Every 3rd column is hidden or unhidden for 75 column occurrences.
I'm using the code below for now, BUT IT TAKES FOREVER!
I think the key is to select multiple columns first and then hide or unhide the selection. The problem is, I can do it manually, but the code captured by the macro recorder doesn't work BECAUSE THERE ARE MERGED CELLS ACROSS THE COLUMNS.
Assume some row has the following cells merged.
A,B,C D,E,F G,H,I J,K,L M,N,O
and I want to hide a column in each merged range.
Here's what the recorder captured:
Range("B:B,E:E,H:H,K:K,N:N".Select
Range("N1".Activate
Selection.EntireColumn.Hidden = True (or FALSE)
This doesn't work when placed in a macro. It selects AND HIDES ALL COUMNS IN THE MERGED RANGE.
I APPRECIATE ANY HELP!!!!!
Thanks!
TMKTECH
--------------- Current Code ------------------
Sub Hide_Show_Cols(ByVal margin_chg As Boolean, ByVal amt_chg As Boolean, ByVal cap_chg As Boolean):
margin_col = [Col1_Margin].Column 'set initial columns
amt_col = [Col1_Amt].Column
cap_col = [Col1_Cap].Column
For c = 1 To 75
If margin_chg Then
Columns(margin_col).Hidden = _
IIf([Show_Margin] = True, False, True)
End If
If amt_chg Then
Columns(amt_col).Hidden = _
IIf([Show_Amt] = True, False, True)
End If
If cap_chg Then
Columns(cap_col).Hidden = _
IIf([Show_Cap] = True, False, True)
End If
margin_col = margin_col + 3 'set up starting columns
amt_col = amt_col + 3
cap_col = cap_col + 3
Next
End Sub