Putting macros together

  • Thread starter saman110 via OfficeKB.com
  • Start date
S

saman110 via OfficeKB.com

How do you guys put or run two macros together in one macro. I have to
separate macros that i want to run one after each other in one macro.


Sub DeleteColumns()
Dim i As Integer

For i = 256 To 1 Step -1
If Cells(1, i).Text = "Rank" Or _
Cells(1, i).Text = "Housing units" Or _
Cells(1, i).Text = "Occupied Housing Units" Or _
Cells(1, i).Text = "Vacant Housing Units" Then
Cells(1, i).EntireColumn.Delete
End If
Next i
End Sub

----------------------and

Sub DeleteColumns()
Dim i As Integer

For i = 256 To 1 Step -1
If Cells(2, i).Text = "Subtotal of High" Or _
Cells(2, i).Text = "Subtotal of Extremely High" Or _
Cells(2, i).Text = "Subtotal of Average" Or _
Cells(2, i).Text = "Subtotal of Below Average" Or _
Cells(2, i).Text = "Subtotal of Above Average" Or _
Cells(2, i).Text = "Grand Total" Then
Cells(2, i).EntireRow.Delete
End If
Next i
End Sub
 
D

Don Guillett

Just put em together or call the 2nd from the first
Again, Look at your original post about using rows to delete columns. Slow
down and think about what you are doing.
 
G

Guest

Hi,

First you have to change the name of your second macro to be different than
the name of the first macro.
For example Sub DeleteColumns() and Sub DeleteColumns_2()
Then copy this code:

Sub Run_both_macros()
' Macro recorded 7/24/2007 by Tim
DeleteColumns
DeleteColumns_2
End Sub

Go to your workbook>hit Alt+F11>Double click a module and paste my
code>close VB Editor>Alt+F8 and run macro: Run_both_macros

Regards,

Tim
 
G

Guest

When in VB Editor instead double click a module got to Insert>New Module and
then Paste

Tim
 
S

saman110 via OfficeKB.com

Thank you for your response.

What if you have 3 macros to run?
Hi,

First you have to change the name of your second macro to be different than
the name of the first macro.
For example Sub DeleteColumns() and Sub DeleteColumns_2()
Then copy this code:

Sub Run_both_macros()
' Macro recorded 7/24/2007 by Tim
DeleteColumns
DeleteColumns_2
End Sub

Go to your workbook>hit Alt+F11>Double click a module and paste my
code>close VB Editor>Alt+F8 and run macro: Run_both_macros

Regards,

Tim
How do you guys put or run two macros together in one macro. I have to
separate macros that i want to run one after each other in one macro.
[quoted text clipped - 28 lines]
Next i
End Sub
 
D

Don Guillett

Same thing for 30


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
saman110 via OfficeKB.com said:
Thank you for your response.

What if you have 3 macros to run?
Hi,

First you have to change the name of your second macro to be different
than
the name of the first macro.
For example Sub DeleteColumns() and Sub DeleteColumns_2()
Then copy this code:

Sub Run_both_macros()
' Macro recorded 7/24/2007 by Tim
DeleteColumns
DeleteColumns_2
End Sub

Go to your workbook>hit Alt+F11>Double click a module and paste my
code>close VB Editor>Alt+F8 and run macro: Run_both_macros

Regards,

Tim
How do you guys put or run two macros together in one macro. I have to
separate macros that i want to run one after each other in one macro.
[quoted text clipped - 28 lines]
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top