ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Another Hide Columns Question (https://www.excelbanter.com/excel-discussion-misc-queries/183927-another-hide-columns-question.html)

Dallas PM

Another Hide Columns Question
 
I am running Excel 2003 and need help with a macro. I have a table consisting
of Region, Stores and Monthly Sales. I wrote a macro to filter (hide) Stores
depending on the Region.

Region Store Sales City
Region1 Store1 $170K City1
Region1 Store2 $160K City2
Region2 Store1 $220K City1
Region2 Store3 $250K City1
Region3 Store1 $200K City2

In the following macro, the target value of A1 (Region) is located on
another worksheet, but I want to use that information to hide the Store
(column) that are not in the Region. When I run the macro, there is no change
in the results.

Any help would be greatly appreciated

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
Range("A:D").EntireColumn.Hidden = False
If Target.Value = "Region1" Then
Range("A:B").EntireColumn.Hidden = True
Range("C:D").EntireColumn.Hidden = False
Else
Range("A:B").EntireColumn.Hidden = False
Range("C:D").EntireColumn.Hidden = True
End If
End If
End Sub



Bernie Deitrick

Another Hide Columns Question
 
Copy the code below, right click the tab of the "another worksheet" where A1 is located, select
"View Code" and paste the code into the window that appears.

My code assumes that the sheet with the data table is named "Data", and that the table starts in
cell A1.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
Worksheets("Data").Range("A1").CurrentRegion.AutoF ilter Field:=1, Criteria1:=Target.Value
End If
End Sub


"Dallas PM" wrote in message
...
I am running Excel 2003 and need help with a macro. I have a table consisting
of Region, Stores and Monthly Sales. I wrote a macro to filter (hide) Stores
depending on the Region.

Region Store Sales City
Region1 Store1 $170K City1
Region1 Store2 $160K City2
Region2 Store1 $220K City1
Region2 Store3 $250K City1
Region3 Store1 $200K City2

In the following macro, the target value of A1 (Region) is located on
another worksheet, but I want to use that information to hide the Store
(column) that are not in the Region. When I run the macro, there is no change
in the results.

Any help would be greatly appreciated

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
Range("A:D").EntireColumn.Hidden = False
If Target.Value = "Region1" Then
Range("A:B").EntireColumn.Hidden = True
Range("C:D").EntireColumn.Hidden = False
Else
Range("A:B").EntireColumn.Hidden = False
Range("C:D").EntireColumn.Hidden = True
End If
End If
End Sub





Dallas PM

Another Hide Columns Question
 
TY for the response. I am looking to view the profitability of each store
collectively and by region with the end result looking similar to:

Region1 (A1)

City1 City2
Store1 $170K
Store2 $160K


Region2 (A1)

City1
Store1 $220K
Store3 $250K


Region3 (A1)


City2
Store1
$200K


Region0 (A1)

City1 City2 City1 City2
Store1 $170K
Store2 $160K
Store1 $220K
Store3 $250K
Store1 $200K


"Bernie Deitrick" wrote:

Copy the code below, right click the tab of the "another worksheet" where A1 is located, select
"View Code" and paste the code into the window that appears.

My code assumes that the sheet with the data table is named "Data", and that the table starts in
cell A1.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
Worksheets("Data").Range("A1").CurrentRegion.AutoF ilter Field:=1, Criteria1:=Target.Value
End If
End Sub


"Dallas PM" wrote in message
...
I am running Excel 2003 and need help with a macro. I have a table consisting
of Region, Stores and Monthly Sales. I wrote a macro to filter (hide) Stores
depending on the Region.

Region Store Sales City
Region1 Store1 $170K City1
Region1 Store2 $160K City2
Region2 Store1 $220K City1
Region2 Store3 $250K City1
Region3 Store1 $200K City2

In the following macro, the target value of A1 (Region) is located on
another worksheet, but I want to use that information to hide the Store
(column) that are not in the Region. When I run the macro, there is no change
in the results.

Any help would be greatly appreciated

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
Range("A:D").EntireColumn.Hidden = False
If Target.Value = "Region1" Then
Range("A:B").EntireColumn.Hidden = True
Range("C:D").EntireColumn.Hidden = False
Else
Range("A:B").EntireColumn.Hidden = False
Range("C:D").EntireColumn.Hidden = True
End If
End If
End Sub







All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com