Macro to delete row based on cell criteria

MPFX2022

New Member
Joined
Nov 24, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Greetings all,
Ive done a search here but cant find what Im looking for.

I need a macro to search Column J, find any cells that contain the word "Full" and then delete that entire row.

Any help would be greatly appreciated 🙏🙏
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try this on a copy of your Workbook.
VBA Code:
Option Explicit

Const fnd As String = "Full"

Sub DeleteWordFull()
Dim lRow As Long, i As Long

lRow = Columns("J").Rows.End(xlDown).Row


For i = lRow To 1 Step -1
    If Range("J" & i).Value = fnd Then Rows(i).Delete
Next i

End Sub
 
Upvote 0
Solution
Hi there,

I'm surprised you couldn't find a macro to delete the applicable row(s) as I know I have answered numerous threads asking a very similar request.

That said try this (initially on a copy of your data as the results cannot be undone if they're not as expected):

VBA Code:
Option Explicit
Sub Macro1()

    Dim ws As Worksheet
    Dim rngCell As Range, rngDelete As Range
   
    Application.ScreenUpdating = False
   
    Set ws = ThisWorkbook.Sheets("Sheet1") 'Name of sheet where the rows are to be deleted from. Change to suit if necessary.
   
    With ws
        For Each rngCell In .Range("J2:J" & .Range("J" & Rows.Count).End(xlUp).Row)
            If Trim(StrConv(rngCell, vbLowerCase)) = "full" Then
                If rngDelete Is Nothing Then
                    Set rngDelete = rngCell
                Else
                    Set rngDelete = Union(rngDelete, rngCell)
                End If
            End If
        Next rngCell
    End With
   
    'If the 'rngDelete' range has been set, then...
    If Not rngDelete Is Nothing Then
        '...delete the row(s) from it.
        rngDelete.EntireRow.Delete
    'Else...
    Else
        '...inform the user that no rows were deleted as there were no matching criteria within the dataset.
        MsgBox "There were no rows deleted as no there were no entries with the text ""Full"".", vbExclamation
    End If
   
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Thank you Both so much. Worked perfectly 🙏 🙏

I did search many times, perhaps the wording was wrong, But again, thank you both for your help
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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