Hide a Range of Cells in Excel using Macro

peoplesoft

New Member
Joined
May 12, 2011
Messages
5
Hello

I have seen various types of Logic to Hide Rows and Columns in Excel, I am already Using a Dirty Way of doing it. But I was thinking maybe someone can help me build a better way of Doing it.
Here is a sample Data:
HTML:
https://picasaweb.google.com/lh/photo/eGI3mjH5jRRGZtrQZOT_x69YdAVc8bz5Ke_LoJMPuVQ?feat=directlink
Basically my request is to Find the "Start-P&L" and "End-P&L" Texts and Hide the Entire Row and Columns of that Range B3:F10. The Cell Position is not Constant so it is Key that I find these Texts and then Hide the Corresponding Cells.
If I can Hide the Range (B3:F10) it will be Awesome too. But I don't Know if that can be done or not.
I hard coded the Cells with a text "BS"
My Code as You see from the screenshot is something like this:

Sub HideRows1()
Dim cell As Range
For Each cell In Range("A:IV")
If UCase(cell.Value) = "BS" Then
cell.EntireRow.Hidden = True
cell.EntireColumn.Hidden = True
End If
Next
End Sub

Please Help
Thanks in Advance
Peoplesoft Guy
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
Sub G()

    Dim rngTopLeft As Range, rngBottomRight As Range
    
    With Sheets(1).Cells
        Set rngTopLeft = .Find(What:="Start-P&L")
        Set rngBottomRight = .Find(What:="End-P&L")
        With .Range(rngTopLeft, rngBottomRight)
            .EntireRow.Hidden = True
            .EntireColumn.Hidden = True
        End With
    End With

End Sub
 
Last edited:
Upvote 0
Thanks Sektor - I think this works for me -
I will try this on my Full Sheet of Data first.
Range("BS").EntireRow.Hidden = True
Range("BS").EntireColumn.Hidden = True

My Range is not Constant as my process Adds rows in Between - But if I use the Range name it gets added to it automatically. So I am hoping this should work Just Fine.

Once Again Thanks
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

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