Solved

Add two simple VBA scripts to one in excel macro

Posted on 2013-01-29
5
355 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
ID: 38833914
Sub main()

    hidecols

    unhidecols

end sub
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 250 total points
ID: 38833951
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
ID: 38834234
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
ID: 38837419
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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