skip code if not blank cell

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
peace all,

with the code :=

Code:
    Range("1:1,51:51,101:101,151:151").Delete Shift:=xlUp

how to check individual range from above if blank or not, and then apply deletion to that particular range.

for instance


1:1 = not blank, then skip code
51:51 = blank, then delete shift:=xlUp
101:101 = not blank, then skip code
151:151 = not blank, then skip code
 
Updated with some corrections.


Code:
Sub Delete()
    Dim x As Long
    Dim y As Long
    Dim z As Long
    Dim lr As Long
    Dim cellrow As Range
    
    For x = 1 To 151 Step 50
        
            Cells(x, 1).Select
            Set cellrow = Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 255))
            z = Application.WorksheetFunction.CountA(cellrow)
            lr = Range(Cells(x, 1), Cells(x, 1).End(xlDown)).Count
            
            If z = 0 Then
            For y = 1 To lr
            Set cellrow = cellrow.Resize(y)
            cellrow.Select ' Checking resize
            z = Application.WorksheetFunction.CountA(cellrow)
            If z > 0 Then
            Set cellrow = cellrow.Resize(y - 1)
            cellrow.Delete shift:=xlShiftUp
            y = lr
            End If
            Next y
            End If
    Next x
End Sub
[/QUOTE]


I appreciate the code. Working like it should now..
:):)
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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