Adapt code VBA to hide columns instead of rows

LordVoldetort_IV

New Member
Joined
Jun 10, 2021
Messages
38
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub Hide_Rows()

With Worksheets("Tax Calculation")


'BeginRow = from which row you want to start checking

'EndRow = to which row you want to check

'ChkCol = in which collom is the value to check



BeginRow = 1

EndRow = 160

ChkCol = 19



For RowCnt = BeginRow To EndRow

If Worksheets("Tax Calculation").Cells(RowCnt, ChkCol).Value = "HIDE" Then

Worksheets("Tax Calculation").Cells(RowCnt, ChkCol).EntireRow.Hidden = True

Else: Worksheets("Tax Calculation").Cells(RowCnt, ChkCol).EntireRow.Hidden = False

End If

Next RowCnt

End With

 End Sub

Hello! the above code is what i use to hide a row based on a value in the same row, but different column. I want to switch it around and hide a column based on a value in the same column, different row. i cant seem to figure it out, would appreciate any help!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Which column(s) & row(s)?
 
Upvote 0
Ok, how about
VBA Code:
Sub LordVoldetort()
   Dim Cl As Range
   
   For Each Cl In Range("A100:H100")
      Cl.EntireColumn.Hidden = Cl.Value = "HIDE"
   Next Cl
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub LordVoldetort()
   Dim Cl As Range
  
   For Each Cl In Range("A100:H100")
      Cl.EntireColumn.Hidden = Cl.Value = "HIDE"
   Next Cl
End Sub
If i want to do the reverse, (to unhide those same columns), how would i go about that?
 
Upvote 0
Like
VBA Code:
   Range("A:H").EntireColumn.Hidden = False
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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