Loop code to delete all blank cells in multiple worksheets

Lizard07

Board Regular
Joined
Jul 20, 2011
Messages
103
Hi - How would I make the below code loop through multiple worksheets in a workbook. The number worksheets varies every time

Option Explicit

Sub DeleteBlanks()
Dim intCol As Integer

intCol = 8
Range(Cells(15, intCol), Cells(40, intCol)). _
SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
End Sub


Thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try

Code:
Sub DeleteBlanks()
Dim intCol As Integer, ws As Worksheet

intCol = 8
For Each ws In ActiveWorkbook.Worksheets
    ws.Range(ws.Cells(15, intCol), ws.Cells(40, intCol)). _
SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
Next ws
End Sub
 
Upvote 0
code to delete all blank cells in a range

Hi Folks,
I have been searching the history for something like this.


how can i adapt this for a range of cells A1:W500

dont know how to read the above intcol=8
so asking for help on this thread. sorry if i have broken a rule ref to new threads, but didnt see anythng as close as this in my searches.

Marty
 
Upvote 0
No rules broken - in fact we encourage members to post follow-ups to their original thread, so well done. Try

Code:
Sub DeleteBlanks()
ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Range("A1:W50").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,563
Messages
6,179,527
Members
452,923
Latest member
JackiG

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