Run One Macro or Another From Worksheet Button

SSP

New Member
Joined
Mar 5, 2009
Messages
2
I hope someone can help.

I have a spreadsheet (don't we all) that contains X number of rows, on the sheet I want to have a single button to extract the rows as .csv.

In essence what I want to happen when the button is clicked is for Macro A to run if there are less than X rows and Macro B to run if there are X rows or more. In my instance X will be 2.

Obvoiously this is easy of one uses 2 buttons but that isn't neat enough for my solution.

Cheers,

Matt
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Matt

Why do you need 2 macros?

Why not just check for the number of rows in the command button click event and then act accordingly?
 
Upvote 0
Hi Matt,

Welcome to the board.

Here is a suggestion to use your two macros:
Code:
Sub RowCheck()
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    If LastRow < 2 Then
        Call MacroA
    Else
        Call MacroB
    End If
End Sub
You can assign this code to your existing button, or, as Norie suggests, incorporate checking the row count and your macros "A" and "B", into the button's event code.
 
Upvote 0
Many thanks for the suggestions I'l give both a try to increase my knowledge.

Cheers,

Matt
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top