Solved

Add two simple VBA scripts to one in excel macro

Posted on 2013-01-29
5
367 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
[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
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

710 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