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
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,113,955
Messages
5,545,162
Members
410,667
Latest member
Gaexel
Top