Find Method to Delete Row

avd88

Board Regular
Joined
Jan 18, 2016
Messages
112
Hi,

I'm trying to use the find method to look in another sheet for a value in a selected row that will be stored in a variable.
Once the macro finds that value it should delete the entire row.

VBA Code:
Private Sub IDNRemoveFlagButton_Click()
    Dim y As Integer
    Dim varId As String
    
    y = ActiveCell.Row
    varId = ActiveSheet.Cells(y, 1).Value
    
    Dim mbResult As Integer
    mbResult = MsgBox("Unflag " & varId & "?", _
    vbYesNo)

    Select Case mbResult
        Case vbYes
    
        Case vbNo
        Exit Sub

    End Select


    'CLEAR FLAG'

    If ActiveSheet.Name = "IDN" Then

        Here is where I need to find varId on the sheet IDN_ column A:A and once it finds it delete that row.

    If ActiveSheet.Name = "BT" Then

        Same thing...

    End If
End Sub

Thanks for the help!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Your code is incomplete so it may be more difficult for me to see what all is going on.

Looks like your wanting to search column A in a sheet for a value that is saved into 'varId'. If that value is found in the column A, you want to delete that row from that sheet that has the value in column A? After you find the value, do you want to continue to search that column A for more matches, or will there be only one possible match to find?

You may also want to look here <--- for a very similar thread.
 
Upvote 0
The following code should do the find/delete for your sheet called 'IDN':

VBA Code:
    Dim LastRowInRange  As Long, RowCounter As Long
'
    LastRowInRange = Sheets("IDN").Range("A:A").Find("*", , xlFormulas, , xlByRows, xlPrevious).Row            ' Returns a Row Number
'
    For RowCounter = 1 To LastRowInRange                                ' Increment through cells in Column A
        If Sheets("IDN").Range("A" & RowCounter) = varId Then           '   If Cell matches our 'Delete if' value then
            Sheets("IDN").Rows(RowCounter).EntireRow.Delete             '       Delete the row
            Exit For
        End If
    Next
 
Last edited:
Upvote 0
Sorry I forgot the 'Exit For', it is corrected now.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

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