blackorchids2002
Board Regular
- Joined
- Dec 29, 2011
- Messages
- 138
Hi,
I badly needing your help coz most of you here are already an expert in writing vba codes.
I have an excel file where I need to show 13 months rolling in my report. Then, have written a code where originally it will just hide or unhide columns depending on the reporting month I selected in the control sheet. So let say, if I would choose November month end, in the "Report" sheet, it will display the data from November 2010 to November 2011. The rest of the months are hidden. I don't have a problem with that part. Now, I would also want to apply the same procedure in grouping or ungrouping columns.
I've got an error in my code if I have to select previous months when it comes to group/ungroup columns.
Sub Hide_UnHide_Col()
Sheets("Report").Select
Range("A2").Select
ActiveCell.FormulaR1C1 = "1"
Range("B2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]+1"
Range("B2").Select
Selection.Copy
Range("C2:AB2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Columns("C:AB").Select ' this is the range of the columns
If Selection.Columns.Group = False Or Selection.Columns.Ungroup = isnothing Then
End If
Selection.Columns.Ungroup
Selection.EntireColumn.Hidden = False
Range("D6").Select
hcol = 16 + Sheets("List").Range("H1")
lcol = hcol - 14
ActiveSheet.Range(Cells(2, 3), Cells(2, lcol)).Select ' this is to hide/unhide columns
Selection.Columns.Group
Selection.EntireColumn.Hidden = True
ActiveSheet.Range(Cells(2, hcol), Cells(2, 28)).Select ' this is to hide/unhide columns
Selection.Columns.Group
Selection.EntireColumn.Hidden = True
Rows("2:2").Select
Selection.ClearContents
Range("D6").Select
Sheets("Control").Select
Range("C4").Select
End Sub
I would appreciate your help on this..
Thanks,
Blackorchids
I badly needing your help coz most of you here are already an expert in writing vba codes.
I have an excel file where I need to show 13 months rolling in my report. Then, have written a code where originally it will just hide or unhide columns depending on the reporting month I selected in the control sheet. So let say, if I would choose November month end, in the "Report" sheet, it will display the data from November 2010 to November 2011. The rest of the months are hidden. I don't have a problem with that part. Now, I would also want to apply the same procedure in grouping or ungrouping columns.
I've got an error in my code if I have to select previous months when it comes to group/ungroup columns.
Sub Hide_UnHide_Col()
Sheets("Report").Select
Range("A2").Select
ActiveCell.FormulaR1C1 = "1"
Range("B2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]+1"
Range("B2").Select
Selection.Copy
Range("C2:AB2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Columns("C:AB").Select ' this is the range of the columns
If Selection.Columns.Group = False Or Selection.Columns.Ungroup = isnothing Then
End If
Selection.Columns.Ungroup
Selection.EntireColumn.Hidden = False
Range("D6").Select
hcol = 16 + Sheets("List").Range("H1")
lcol = hcol - 14
ActiveSheet.Range(Cells(2, 3), Cells(2, lcol)).Select ' this is to hide/unhide columns
Selection.Columns.Group
Selection.EntireColumn.Hidden = True
ActiveSheet.Range(Cells(2, hcol), Cells(2, 28)).Select ' this is to hide/unhide columns
Selection.Columns.Group
Selection.EntireColumn.Hidden = True
Rows("2:2").Select
Selection.ClearContents
Range("D6").Select
Sheets("Control").Select
Range("C4").Select
End Sub
I would appreciate your help on this..
Thanks,
Blackorchids