Macro to hide a column based on criteria

dtryon

New Member
Joined
Feb 26, 2019
Messages
3
I need help trying to auto hide a column based on a group of cells

for example i need it to hide column J if all cells J19:J200 return blanks.

Thank you for any help
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try:
Code:
Sub HideCol()
    If WorksheetFunction.CountA(Range("J19:J200")) = 0 Then Columns("J").Hidden = True
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
Maybe
Code:
Sub dtryon()
Columns(10).Hidden = Application.CountA(Range("J19:J200")) = 0
End Sub
 
Upvote 0
Thank you, this works if i delete my formulas out of the cells, is there a way to keep the formulas and have it hide based on if the formula returns a blank?
 
Upvote 0
How about
Code:
Sub dtryon()
Columns(10).Hidden = Application.CountBlank(Range("J19:J200")) = 182
End Sub
 
Upvote 0
How about
Code:
Sub dtryon()
Columns(10).Hidden = Application.CountBlank(Range("J19:J200")) = 182
End Sub


Awesome that worked. Thank you.

One last question. now if i wanted to use that for multiple columns would i just past it over and over replacing column number and the range? and how do i get it to run auto...thanks again for the help. i am very early in my VBA learning
 
Upvote 0
Which columns would you want it to work on & would it be the same rows each time?
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,923
Members
448,533
Latest member
thietbibeboiwasaco

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