VBA Code to Delete 4 Cells

CXOasis

New Member
Joined
Feb 11, 2022
Messages
4
Office Version
  1. 365
Platform
  1. MacOS
Hey i am new here and fairly new to excel, I have a problem with my file and was wondering if anyone could help me with some code. I have 1 column (A) and in this column there is about 50K prices. What i am trying to achieve is to clear the contents of 4 cells at a time - So for example the first price is in A2 i need to clear the 4 cells below, then leave the price in A7 then move on to clear the next 4 cells and so on until it reaches the bottom of the column. So it clears 4 cells at a time and leaves one value. Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Your subject title says delete 4 cells But then you say:
is to clear the contents of 4 cells

Clear and delete are not the same.
So which is it clear or delete.
 
Upvote 0
Sorry i need to clear them , Not delete , Many thanks for your reply
 
Upvote 0
Maybe something like the code below. Test on a copy of your data

VBA Code:
Sub Clear4Cells()

    Dim LastRow As Long, wRng As Range, iRow As Long
    LastRow = Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row

    For iRow = 3 To LastRow Step 5
        If wRng Is Nothing Then
            Set wRng = Cells(iRow, "A").Resize(4)
        Else
            Set wRng = Union(wRng, Cells(iRow, "A").Resize(4))
        End If
    Next iRow

    If Not wRng Is Nothing Then
        wRng.ClearContents
    End If

End Sub
 
Upvote 0
Solution
Assuming You mean clear:
Try this:
VBA Code:
Sub Clear_Four_Cells()
'Modified 2/11/2022  4:08:55 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

For i = 3 To Lastrow Step 8
    Cells(i, 1).Resize(4).Clear
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,945
Members
449,095
Latest member
nmaske

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