Loop based on cell value

gerald24

Board Regular
Joined
Apr 28, 2017
Messages
95
Hi,

Can anyone look into this? It is not working.
Basically, what I need is to delete every "Test" in a specific range that may change based on Range("A1").
If my understanding is correct, I wanted to set it up in Row 2 up to the last row, and any column based on A1 Value.

HTML:
Sub TEST()

    Dim cl As Range
    Dim Cell As Range
    Dim RngA As Range
    Dim RngB As Range
    
  LastRow = findLastRow(Sheets("Sheet1"))
  Set RngA = Cell(2, Range("A1").Value)
  Set RngB = Cell(2, LastRow)

            For Each cl In Range(RngA, RngB)
                If cl.Value = "Test" Then
                cl.EntireRow.Delete
                Else
                End If
            Next cl

End Sub

Set Function Last Row
HTML:
Function findLastRow(sheet As Worksheet) As Integer
    Set r = sheet.Cells.Find("*", sheet.Range("A1"), xlFormulas, , xlByRows, xlPrevious)
    If Not r Is Nothing Then
        findLastRow = r.Row
    Else
        findLastRow = 0
    End If
End Function


Thanks in advance!!!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,650
Messages
6,126,019
Members
449,280
Latest member
Miahr

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