1
votes

Is there a method to delete a whole row based upon a cell in it using VBA?

Trying to complete the following task:

  1. Select whole row based upon a cell in it in my case cell value <3
  2. Delete entire row

I used CF to achieve the first part, but when trying to delete the highlighted cells (color from CF), the color cannot be found by the Find Function.

Can anyone redirect me to a specific post please been looking for hours.
Danke

1
See HERE and instead of looking for the color just look at the cell in the row and test if <3. - Scott Craner
Thank you, gonna give it a try right away - Enrik S
Scott it aint going to work because: For e.g ColumnA= Name, ColumnB= points the goal is to select data from ColumnB, if is less than 3, delete both ColumnA&ColumnB. In the post you suggested, the selection is not extended to entire row (taking into account all columns) - Enrik S
All three methods delete the entire row. You would simply change the if statements to look at column B and see if it is less than 3. It will then delete the entire row. - Scott Craner
O my bad should have tried harder... ty Scott will give VBA Pete s code a try first, then will double check that post again. - Enrik S

1 Answers

0
votes

How about something like this:

Sub Delete3()

Dim F As Integer
Dim Y As Integer
Dim RngCount As Range


Set RngCount = ActiveSheet.Range("COLUMN:COLUMN")
Y = Application.WorksheetFunction.CountA(RngCount)

For F = Y To 1 Step -1

If ActiveSheet.Range("COLUMN" & F).Value < 3 Then
ActiveSheet.Rows(F).EntireRow.Delete
End If

Next F

End Sub

You just need to replace the word COLUMN with the letter of the column where the values are, e.g. "C:C" and "C".