Solved

Add two simple VBA scripts to one in excel macro

Posted on 2013-01-29
5
349 Views
Last Modified: 2013-01-30
I have two simple VBA scripts I am using and they work fine, but I need to run one after the other.  Whats the easiest way to do this in an excel Macro.  

is it easier to put the two in one.. which would work fine, or else how do you tell a macro to run 2 pieces.

Sure it is a no brainer but figured I would ask those smarter.

Other thing is when I run this macro from a different Tab, it runs on the active tab, not the defined sheet.  Sure this is just a error on my part too.

Thanks
Rusty

Sub HideCols()
    Dim r As Long, LastRow As Long
    LastRow = Sheets("Proposal").UsedRange.Rows(Sheets("Proposal").UsedRange.Rows.Count).Row
    For r = LastRow To 2 Step -1
        If Cells(r, 9) = 0 Then
            Rows(r).EntireRow.Hidden = True
        End If
    Next r
End Sub

Sub UnhideCols()
    Dim r As Long, LastRow As Long
    LastRow = Sheets("Proposal").UsedRange.Rows(Sheets("Proposal").UsedRange.Rows.Count).Row
    For r = LastRow To 2 Step -1
        If Cells(r, 9) = 1 Then
            Rows(r).EntireRow.Hidden = False
        End If
    Next r
   
End Sub
0
Comment
Question by:rustyroo
  • 3
5 Comments
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 250 total points
Comment Utility
Sub main()

    hidecols

    unhidecols

end sub
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 250 total points
Comment Utility
To save on iterating the rows twice try:

Sub HideUnhideCols()
    Dim r As Long, LastRow As Long
    LastRow = Sheets("Proposal").UsedRange.Rows(Sheets("Proposal").UsedRange.Rows.Count).Row
    For r = LastRow To 2 Step -1
        If Cells(r, 9) = 0 Then
            Rows(r).EntireRow.Hidden = True
        ElseIf Cells(r, 9) = 1 Then
            Rows(r).EntireRow.Hidden = False
    Next r
End Sub
    
End Sub

Open in new window


Chris
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
I thought the question was
how do you tell a macro to run 2 pieces
because you knew how to
put the two in one.. which would work fine

So the accepted answer should have been that and any other response which helps you should have been an assist.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
Netminder, I have already put my comments up. If they seem to be wrongly interpreted then I shall end the discussion here. Feel free to delete my comment.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 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

18 Experts available now in Live!

Get 1:1 Help Now