Excel VBA excel - find and delete

Joined
Jul 31, 2014
Messages
1
Reaction score
0
Hi there

I am new to VBA on excel. Can someone help please. :cry:

I have a spreadsheet of many columns and rows. I need to find the word "Record Id" (which is normally in column A somewhere) and then delete 10 lines from where the Record ID word is.

Right now I have to do it manually by searching Ctrl + f and then selecting 10 lines and deleting. But if I can have a code, it will be much faster.

Thanks
 
Joined
Nov 11, 2012
Messages
17
Reaction score
1
This code will pop up an imput box, asking what you want to find, will then find it and delete 10 cells below it as well.

Code:
Sub Button1_Click()
    Dim s As String, r As Range
    Dim Rws As Long, Rng As Range
    Rws = Cells(Rows.Count, "A").End(xlUp).Row
    Set Rng = Range(Cells(1, 1), Cells(Rws, 1))
    s = InputBox("What do you want to find?")
    Set r = Rng.Find(what:=s, lookat:=xlWhole)
    Range("A" & r.Row & ":A" & r.Row + 10).Clear

End Sub

You can also use loops to find a criteria.
 
Joined
Feb 21, 2015
Messages
12
Reaction score
1
You can try this code to delete 10 lines from the RecordID

Code:
Sub QuickCull()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Sheets("Sheet1")
Set rng1 = ws.Range(ws.[b2], ws.Cells(Rows.Count, "B").End(xlUp))
Application.ScreenUpdating = False
With ActiveSheet
        .AutoFilterMode = False
        rng1.AutoFilter Field:=1, Criteria1:="Record Id"
        rng1.Offset(1, 0).EntireRow.Delete
        .AutoFilterMode = False
    End With
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top