Hi all,
I need help. How can i write a macro such that
when the user select (e.g. 2 ) from the dropdown for, it hides column
G:Z
when the user select (e.g. 5) from the dropdown form, it hides Column
J:Z
Thank you so much.
Cheers
WL
Hi all,
I need help. How can i write a macro such that
when the user select (e.g. 2 ) from the dropdown for, it hides column
G:Z
when the user select (e.g. 5) from the dropdown form, it hides Column
J:Z
Thank you so much.
Cheers
WL
WL
This macro should do what you want. I wrote the macro so that you could
add conditions and ranges to hide for those conditions. Also, as written,
this macro will hide the designated columns in the sheet that holds the
drop-down and the drop-down is in cell A2. Note that this macro is a sheet
macro and must be placed in the sheet module of that sheet that holds the
drop-down. To access that module, right-click on the sheet tab, select View
Code, and paste this macro into that module. "X" out of the module to
return to the worksheet. HTH Otto
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RngToHide As Range
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Target.Value
Case 2: Set RngToHide = Columns("G:Z")
Case 5: Set RngToHide = Columns("J:Z")
Case Else: Set RngToHide = Range("A1")
End Select
If RngToHide.Address(0, 0) = "A1" Then Exit Sub
Cells.EntireColumn.Hidden = False
RngToHide.EntireColumn.Hidden = True
End If
End Sub
<woeilin.eng@gmail.com> wrote in message
news:1154921970.460978.265190@i3g2000cwc.googlegroups.com...
> Hi all,
>
> I need help. How can i write a macro such that
> when the user select (e.g. 2 ) from the dropdown for, it hides column
> G:Z
> when the user select (e.g. 5) from the dropdown form, it hides Column
> J:Z
>
> Thank you so much.
>
> Cheers
> WL
>
I'm sorry to bother you again..
If the columns to be hidden in another sheet, how shd i go about it??
E.g. The Drop Down is in Sheet "ABC", the columns to be hidden is in
Sheet "Final"
Otto Moehrbach wrote:
> WL
> This macro should do what you want. I wrote the macro so that you could
> add conditions and ranges to hide for those conditions. Also, as written,
> this macro will hide the designated columns in the sheet that holds the
> drop-down and the drop-down is in cell A2. Note that this macro is a sheet
> macro and must be placed in the sheet module of that sheet that holds the
> drop-down. To access that module, right-click on the sheet tab, select View
> Code, and paste this macro into that module. "X" out of the module to
> return to the worksheet. HTH Otto
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim RngToHide As Range
> If Target.Count > 1 Then Exit Sub
> If Not Intersect(Target, Range("A2")) Is Nothing Then
> Select Case Target.Value
> Case 2: Set RngToHide = Columns("G:Z")
> Case 5: Set RngToHide = Columns("J:Z")
> Case Else: Set RngToHide = Range("A1")
> End Select
> If RngToHide.Address(0, 0) = "A1" Then Exit Sub
> Cells.EntireColumn.Hidden = False
> RngToHide.EntireColumn.Hidden = True
> End If
> End Sub
> <woeilin.eng@gmail.com> wrote in message
> news:1154921970.460978.265190@i3g2000cwc.googlegroups.com...
> > Hi all,
> >
> > I need help. How can i write a macro such that
> > when the user select (e.g. 2 ) from the dropdown for, it hides column
> > G:Z
> > when the user select (e.g. 5) from the dropdown form, it hides Column
> > J:Z
> >
> > Thank you so much.
> >
> > Cheers
> > WL
> >
Daphie
Use this macro. Note that the sheet name ABC (the sheet that has the
drop-down cell) does not appear in the macro. You can call it anything you
want.
But the sheet name "Final" does appear in the macro, so if you want to
change that sheet name, you need to change the "Final" in the macro as well.
Note the leading periods in the 2 lines between "With Sheets("Final")" and
"End With". Make sure they are there. HTH Otto
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RngToHide As Range
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Target.Value
Case 2: Set RngToHide = Columns("G:Z")
Case 5: Set RngToHide = Columns("J:Z")
Case Else: Set RngToHide = Range("A1")
End Select
If RngToHide.Address(0, 0) = "A1" Then Exit Sub
With Sheets("Final")
.Cells.EntireColumn.Hidden = False
.Range(RngToHide.Address).EntireColumn.Hidden = True
End With
End If
End Sub
"Daphie" <woeilin.eng@gmail.com> wrote in message
news:1155174498.382763.208070@m79g2000cwm.googlegroups.com...
> I'm sorry to bother you again..
>
> If the columns to be hidden in another sheet, how shd i go about it??
> E.g. The Drop Down is in Sheet "ABC", the columns to be hidden is in
> Sheet "Final"
>
> Otto Moehrbach wrote:
>> WL
>> This macro should do what you want. I wrote the macro so that you
>> could
>> add conditions and ranges to hide for those conditions. Also, as
>> written,
>> this macro will hide the designated columns in the sheet that holds the
>> drop-down and the drop-down is in cell A2. Note that this macro is a
>> sheet
>> macro and must be placed in the sheet module of that sheet that holds the
>> drop-down. To access that module, right-click on the sheet tab, select
>> View
>> Code, and paste this macro into that module. "X" out of the module to
>> return to the worksheet. HTH Otto
>> Private Sub Worksheet_Change(ByVal Target As Range)
>> Dim RngToHide As Range
>> If Target.Count > 1 Then Exit Sub
>> If Not Intersect(Target, Range("A2")) Is Nothing Then
>> Select Case Target.Value
>> Case 2: Set RngToHide = Columns("G:Z")
>> Case 5: Set RngToHide = Columns("J:Z")
>> Case Else: Set RngToHide = Range("A1")
>> End Select
>> If RngToHide.Address(0, 0) = "A1" Then Exit Sub
>> Cells.EntireColumn.Hidden = False
>> RngToHide.EntireColumn.Hidden = True
>> End If
>> End Sub
>> <woeilin.eng@gmail.com> wrote in message
>> news:1154921970.460978.265190@i3g2000cwc.googlegroups.com...
>> > Hi all,
>> >
>> > I need help. How can i write a macro such that
>> > when the user select (e.g. 2 ) from the dropdown for, it hides column
>> > G:Z
>> > when the user select (e.g. 5) from the dropdown form, it hides Column
>> > J:Z
>> >
>> > Thank you so much.
>> >
>> > Cheers
>> > WL
>> >
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks