Hide columns based on values in certain cells

mabubakerali

New Member
Joined
Feb 23, 2016
Messages
43
Office Version
  1. 2024
Platform
  1. Windows
i need macro or whatever solution you people have for the following situation:
in the range g219:gd219 have 0 in that row then hide the column in which that cell is located which have 0, e.g if m219 have value 0 then hide column m and when value changes from 0 then automatically show column back
 
maybe something like this..
Code:
Sub MM1()
Dim lc As Integer
Cells.Columns.Hidden = False
lc = Cells(219, Columns.Count).End(xlToLeft).Column
For c = lc To 1 Step -1
If Cells(219, c).Value = 0 Then Columns(c).EntireColumn.Hidden = True
Next c
End Sub
 
Upvote 0
maybe something like this..
Code:
Sub MM1()
Dim lc As Integer
Cells.Columns.Hidden = False
lc = Cells(219, Columns.Count).End(xlToLeft).Column
For c = lc To 1 Step -1
If Cells(219, c).Value = 0 Then Columns(c).EntireColumn.Hidden = True
Next c
End Sub

it hides all columns having values 0 in row 219, i just want to hide columns from g219:gd219
 
Upvote 0
IS gd219 the last column ??
If so
Code:
Sub MM1()
Dim lc As Integer
Cells.Columns.Hidden = False
lc = Cells(219, Columns.Count).End(xlToLeft).Column
For c = lc To 7 Step -1
If Cells(219, c).Value = 0 Then Columns(c).EntireColumn.Hidden = True
Next c
End Sub
if there are more than "GD" columns use...


Code:
Sub MM1()
Cells.Columns.Hidden = False
For c = 180 To 7 Step -1
If Cells(219, c).Value = 0 Then Columns(c).EntireColumn.Hidden = True
Next c
End Sub
 
Upvote 0
IS gd219 the last column ??
If so
Code:
Sub MM1()
Dim lc As Integer
Cells.Columns.Hidden = False
lc = Cells(219, Columns.Count).End(xlToLeft).Column
For c = lc To 7 Step -1
If Cells(219, c).Value = 0 Then Columns(c).EntireColumn.Hidden = True
Next c
End Sub
if there are more than "GD" columns use...


Code:
Sub MM1()
Cells.Columns.Hidden = False
For c = 180 To 7 Step -1
If Cells(219, c).Value = 0 Then Columns(c).EntireColumn.Hidden = True
Next c
End Sub


Thanks bro you made the day..
THANKS ALOT for your help!
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top