Solved

hide certain rows in Excel Macro

Posted on 2014-10-30
2
275 Views
Last Modified: 2014-10-30
Hi experts,

I have a task in Excel and think it can be accomplished by a macro or two macros, written by VBA, etc. I do not know any new development of VB, such as VB script, or VB.net, etc.

The main tasks are two steps.
1. to hide all rows that with "X" in cell A. For example if A2=X, hide row 2, A34=X, hide row 34.
2. after the hiding, set the print preview for the whole area with non-empty cells.

I image it can be done with a macro and with a click of button to change the normal view to the the print preview mode.

After this is done, we can have a separate button to back to normal view. Or we can add something to the original button for switched views between normal and print preview. It does not matter whether it is two buttons or one button to have it accomplished.

Thanks,
RDB
0
Comment
Question by:ResourcefulDB
2 Comments
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 250 total points
ID: 40413464
Hi,

pls try

Sub Macro()
For Each cel In Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    If cel = "X" Then
        cel.EntireRow.Hidden = True
    Else
        cel.EntireRow.Hidden = False
    End If
Next
ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
End Sub

Open in new window

Regards
0
 
LVL 31

Accepted Solution

by:
Rob Henson earned 250 total points
ID: 40413585
No need for VBA.

You can just put an Auto Filter on Col A to Hide rows containing X.

Then there is standard Print Preview and Normal View buttons on the View Ribbon.

Thanks
Rob H
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
This collection of functions covers all the normal rounding methods of just about any numeric value.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now