Compare date in a cell to a variable, then delete row.

dhosi439

Board Regular
Joined
May 13, 2009
Messages
62
Is it possible to compare data in a range of cells to a concatenated variable in vba, if it is found then delete the entire row, otherwise do nothing.

For example,

range is A:A, value to be located is B27_3/17/2010

variables are test1 and test2

test1 = B27 test2 = 3/17/2010

the concatenated would look like this: test1 & "_" & test2 or 'B27_3/17/2010'

I need to look in column A for the concatenated variables, if it is found then the row containing that value must be deleted.

Not sure how to search for the value in the range.

The values are in a table and column A is the first column of the table and this can be a named range, if this makes it easier.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Does Row 1 contain column labels/headers? If not, include the labels/headers, and then try...

Code:
Sub test()

    Dim FoundCells As Range
    Dim test1 As String
    Dim test2 As String
    
    test1 = "B27"
    test2 = "3/17/2010"
    
    Application.ScreenUpdating = False
    
    With ActiveSheet.UsedRange
        .AutoFilter field:=1, Criteria1:=test1 & "_" & test2
        On Error Resume Next
        Set FoundCells = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        If Not FoundCells Is Nothing Then
            FoundCells.EntireRow.Delete
        Else
            MsgBox "No cells were found..."
        End If
        .AutoFilter
    End With
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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