Solved

hide certain rows in Excel Macro

Posted on 2014-10-30
2
279 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 49

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 32

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

910 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

20 Experts available now in Live!

Get 1:1 Help Now