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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,175,656
Messages
5,898,723
Members
434,724
Latest member
DJT

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