ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find item and delete rows (https://www.excelbanter.com/excel-programming/295691-find-item-delete-rows.html)

Joseph[_28_]

Find item and delete rows
 
VBA help needed for a beginner.

I need to find a first instance of a string in first column and then
to delete all the rows from the one in which the string was found to
the end of the spreadsheet.

Thanks,

Joseph

Ron de Bruin

Find item and delete rows
 
Hi Joseph

Try this example for column A

Sub Find_First()
Dim FindString As String
Dim Rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) < "" Then
Set Rng = Range("A:A").Find(What:=FindString, _
After:=Range("A" & Rows.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then Rows(Rng.Row & ":" & Rows.Count).Delete
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Joseph" wrote in message om...
VBA help needed for a beginner.

I need to find a first instance of a string in first column and then
to delete all the rows from the one in which the string was found to
the end of the spreadsheet.

Thanks,

Joseph





All times are GMT +1. The time now is 03:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com