Applying macro/vba to run on multiple worksheets and not only the current worksheet

Status
Not open for further replies.

jia22

New Member
Joined
Nov 22, 2017
Messages
5
Hello Everyone!
I have a code here(please find below) and was wondering if you could help out.

I am using this code to delete all the blank rows in a worksheet , and this code works fine.

The problem I am Having is that, when I run the code it only does it for the current worksheet I am on. I have around 13 worksheets in my workbook and was wondering if it could be applied to all the active worksheets when I run the macro once, without having to run the macro for each worksheet.

Any help is much appreciated! Thank you in advance!

You make changes to the code directly =)




Public Sub DeleteRowFINAL()

Application.ScreenUpdating = False

For Each usedrng In ActiveSheet.UsedRange

If usedrng.MergeCells = True Then
If usedrng.Value = "" Then
usedrng.Value = ""
End If
Else
If usedrng.Value = "" Then
usedrng.ClearContents
End If
End If
Next

ActiveSheet.UsedRange
usedRangeLastColNum = ActiveSheet.UsedRange.Columns.<wbr>Count
usedrangelastrow = ActiveSheet.UsedRange.Rows.<wbr>Count

For r = usedrangelastrow To 1 Step -1
If Application.WorksheetFunction.<wbr>CountA(Cells(r, usedRangeLastColNum).<wbr>EntireRow) <> 0 Then

Exit For
Else
Cells(r, usedRangeLastColNum).<wbr>EntireRow.Delete
End If
Next r

For c = usedRangeLastColNum To 1 Step -1
If Application.WorksheetFunction.<wbr>CountA(Cells(1, c).EntireColumn) <> 0 Then

Exit For
Else
Cells(1, c).EntireColumn.Delete
End If
Next c

ActiveSheet.UsedRange
Application.ScreenUpdating = True

Dim rgCol As Range

On Error Resume Next

For Each rgCol In Range("A2:G102").Columns
rgCol.SpecialCells(<wbr>xlCellTypeBlanks).EntireRow.<wbr>Delete
Next rgCol

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
jia22: this thread is a duplicate of: https://www.mrexcel.com/forum/excel...ly-macro-multiple-worksheets.html#post4956774, to which you have already had numerous replies.

Kindly read Mr Excel's policy against running duplicate threads, in Rule 12: http://www.mrexcel.com/forum/board-announcements/99490-forum-rules.html

Furthemore, kindly also read rule 14, regarding posting in a way that is "consistent with ‘normal writing’". Your excessive use of bold & colouring does not conform.

Finally, when posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.

I am closing this thread and moving the discussion to your original thread. You may continue the discussion there.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

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