Solved

Add two simple VBA scripts to one in excel macro

Posted on 2013-01-29
5
362 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

713 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