Hide two columns if one is blank

ILoveCheese

New Member
Joined
Mar 27, 2008
Messages
27
Currently using this code to search Column D and hide if the cells are blank. How would I go about also hiding Column C as well, If D is blank?

I am using the spreadsheet as a grading template. The assignment name is under column C and the grade under column D. If there is no grade then I would like to be able to hide the unused assignment column along with the empty grade column.

Code:
Sub HideColumnsInd()
With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With
Dim rCell As Range
For Each rCell In Range("D3:D48")
    If rCell = "" Then
        rCell.EntireColumn.Hidden = True
    Else
        rCell.EntireColumn.Hidden = False
    End If
Next rCell
Application.EnableEvents = True
End Sub

Any help would be appreciated.

Thank you.
 
Knew it could be cleaner, just change the range to D3:D48, since it should only be looking at column D.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,412
Messages
6,124,761
Members
449,187
Latest member
hermansoa

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