Solved

hide certain rows in Excel Macro

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

777 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