View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Searching for a word and then copy the whole row

Hi Kaj,

Am Thu, 28 Feb 2013 08:58:59 +0100 schrieb KP:

1. Search the word "test" in specified selection (A3:G68)
2. When found, then copy the whole row in which the word was found to "A100"
3. Next look up for the word "test", and when found copy the whole row to
"A101"
4. Continue serch for the word "test" and copy to "A102" and so on until no
more is found.


try:

Sub myCopy()
Dim i As Integer
Dim c As Range
Dim firstAddress As String

i = 100
With Range("A3:G68")
Set c = .Find("test", LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Copy Cells(i, 1)
i = i + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2