Solved

hide certain rows in Excel Macro

Posted on 2014-10-30
2
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

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 33

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

739 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