Run same Macro on selected sheets from a click button

Joined
Feb 15, 2013
Messages
8
Hi All,
I have tried to use other posts but due to inexperience was not successful.
I am new to macros, but have managed to run the 2 subs below successfully:

Sub Delete_Empty_Columns()
first = Selection.Column
last = Selection.Columns(Selection.Columns.Count).Column
For i = last To first Step -1
If WorksheetFunction.CountBlank(ActiveSheet.Columns(i)) = 1048576 Then
Columns(i).Delete
End If
Next i
End Sub


Sub SelectData()
'
' SelectData Macro
'

'
Range("A4:EB10").Select
End Sub


I have managed to get them both running by clicking the button using the code below:

Private Sub CommandButton2_Click()
Call SelectData
Call Delete_Empty_Columns
End Sub


What I am trying to achieve is run the above macro on selected sheets within my workbook with the click of a button.

Any help would be great, I am new to macros so apologize if I am using the wrong terminology.

Thanks in advance for any help. :)
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,215,949
Messages
6,127,880
Members
449,411
Latest member
AppellatePerson

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