Macro to to Delete every 4th Row in Column J where there is text

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have have a formula in Col J below from row 2 onwards

Code:
=IF(I2="","",A2)

Where Col J from row 2 onwards contains Text, I need code to find the first text that is not blank and to delete this text as well as every 4th after finding the first text


Macro or Formula to Delete Duplicated Ref Numbers whee Branch is the Same. Ver 1.1xlsm.xlsm
J
1Division
2 
3 
4 
5 
6 
7 
8South End
9South End
10Mayberry
11South End
12South End
13Port Edward
14 
15 
16 
17 
Duplicates
Cell Formulas
RangeFormula
J2:J17J2=IF(I2="","",A2)



In the example above rows 8 & 11 to be deleted

It would be appreciated if someone could assist me
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Your post is a bit confusing as to whether you want to delete the text in specific cells or delete the rows the specific cells are in. Assuming you want to delete the text not the rows, the code below should do that. Please note that col J cells initially hold formulas, deleting the text will remove those formulas with no undo available, so try this on a copy of your sheet.
VBA Code:
Sub DeleteTextIf()
Dim V As Variant, i As Long, Ct1 As Long, x As Long
V = Range("J2:J17").Value  'Expand range to suit
Application.ScreenUpdating = False
For i = LBound(V, 1) To UBound(V, 1)
    If V(i, 1) <> "" Then
        If Ct1 = 0 Then
            Ct1 = i + 1
            x = Ct1 Mod 3
            Cells(Ct1, "J").Value = "#N/A"
        Else
            If (i + 1) Mod 3 = x Then Cells(i + 1, "J").Value = "#N/A"
        End If
    End If
Next i
On Error Resume Next
Range("J2:J17").SpecialCells(xlCellTypeConstants, xlErrors).ClearContents
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for the help.

I have written a macro to range value the items in ColJ. Kindly amend you code to find the first Text , delete this row and thereafter every 4th row after find the first text

Macro to find Text & Delete Every 4th Items thereafrer in Col C every 1st triplicate IOtem).xlsm
IJ
1TriplicateDivision
2
3
4
5
6
7
8DeleteBR Bay West
9DeleteBR Bay West
10DeleteBR South Coast
11BR Bay West
12DeleteBR Bay West
13DeleteBR South Coast
14
15
16
17
Duplicates
 
Upvote 0
Your example appears to want deletion of more than every 4th row. See if this is what you want. If you don't want entire rows deleted, see the comment on the line that deletes.
VBA Code:
Sub DeleteCertainRows()
Dim V As Variant, i As Long, Ct1 As Long, x As Long
V = Range("J2:J17").Value  'Expand range to suit
Application.ScreenUpdating = False
For i = LBound(V, 1) To UBound(V, 1)
    If Ct1 > 0 Then GoTo Nx
    If V(i, 1) <> "" Then
        Ct1 = i + 1
        x = Ct1 Mod 3
        Cells(Ct1, "J").Value = "#N/A"
    End If
Nx:
    If (i + 1) Mod 3 = x Then Cells(i + 1, "J").Value = "#N/A"
Next i
On Error Resume Next
Range("J2:J17").SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete 'change to .Delete shift:= xlup if don't want entire rows deleted
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,853
Messages
6,121,935
Members
449,056
Latest member
denissimo

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