Loop

watkins6878

Board Regular
Joined
Nov 26, 2005
Messages
96
Hi

I am trying to loop through a sheet looking in column "D" for a word and when it find the word i want it to copy the entire row to another sheet but data is being addedall the time . how can i get it to loop until it gets to the last row with data in it. I would be greatful for any help

Thanks

alan
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
try the following code for looping until it gets to the last row with data in it.

Code:
Sub test()
Range("D1").select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0
If the word you are looking for occupies the cells on its own, instead of looping, AutoFilter could be used :-

Code:
With Range([D1], [D65536].End(xlUp))
    .AutoFilter 1, "the word"
    .Offset(1).Resize(.Rows.Count - 1) _
            .SpecialCells(xlVisible).EntireRow.Copy _
            Sheets("Sheet2").[D65536].End(xlUp)(2, -2)
    .AutoFilter
End With

The code assumes you have a header row.
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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