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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
L

Legacy 68403

Guest
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
 

Boller

Banned
Joined
Apr 11, 2006
Messages
2,328
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.
 

Forum statistics

Threads
1,144,522
Messages
5,724,830
Members
422,581
Latest member
samiak

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
Top