ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find a row based on a word in the cell (https://www.excelbanter.com/excel-programming/438708-find-row-based-word-cell.html)

mrsviqt

Find a row based on a word in the cell
 
I would like to search a worksheet for "apple". When it finds "apple", I
want it to select that row, as well as the row below it (which does not
contain the word "apple".) I would like to continue to search until the end
of the worksheet. So, it will find all rows that contain the word "apple",
select that row, as well as the row directly beneath it. Then it needs to
cut these cells and paste into a new worksheet.

The rows will never be the same, but the word "apple" will always occur in
column A. "apple" will never be the first or last word in the cell.

Any help would be greatly appreciated.

JLGWhiz[_2_]

Find a row based on a word in the cell
 
This worked pretty good in testing:

Sub getApple()
Dim lr As Long, sh As Worksheet, rng As Range
Dim sh2 As Worksheet, lr2 As Long, c As Range
Set sh = ActiveSheet
Set sh2 = Sheets("Sheet2")
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:A" & lr)
For Each c In rng
lr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row
If InStr(LCase(c.Value), "apple") 0 Then
c.Resize(2, 1).EntireRow.Copy sh2.Range("A" & lr2 + 1)
End If
Next
End Sub


"mrsviqt" wrote in message
...
I would like to search a worksheet for "apple". When it finds "apple", I
want it to select that row, as well as the row below it (which does not
contain the word "apple".) I would like to continue to search until the
end
of the worksheet. So, it will find all rows that contain the word
"apple",
select that row, as well as the row directly beneath it. Then it needs to
cut these cells and paste into a new worksheet.

The rows will never be the same, but the word "apple" will always occur in
column A. "apple" will never be the first or last word in the cell.

Any help would be greatly appreciated.





All times are GMT +1. The time now is 10:36 AM.

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