Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Searching for a word and then copy the whole row

Hi,

Can someone help to write a macro doing the following:

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.

Thank you in advance.

Kaj Pedersen

  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Searching for a word and then copy the whole row

Hi Claus,

It works perfectly and I got what I was asking for. However, I still have a
little problem.
Is it possible instead of copying the whole row to define the area to be
copied?
(e.g. column A to column G in the actual found row?)

Regards,
Kaj Pedersen


"Claus Busch" skrev i meddelelsen ...

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Searching for a word and then copy the whole row

Hi Kaj,

Am Thu, 28 Feb 2013 10:09:20 +0100 schrieb KP:

Is it possible instead of copying the whole row to define the area to be
copied?
(e.g. column A to column G in the actual found row?)


change c.EntireRow.Copy to:
Range(Cells(c.Row, 1), Cells(c.Row, 7)).Copy


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Searching for a word and then copy the whole row

Hi Claus,

I tried your suggestion but I think something must be missing in the macro.
The selection was copied to clipboard, but nothing was pasted and no new
search for
the next word "test" was carried out.

By the way, I would rather like to to copy from column B to column G instead
of
column A to G.
Is it possible?

Regards,
Kaj Pedersen


"Claus Busch" skrev i meddelelsen ...

Hi Kaj,

Am Thu, 28 Feb 2013 10:09:20 +0100 schrieb KP:

Is it possible instead of copying the whole row to define the area to be
copied?
(e.g. column A to column G in the actual found row?)


change c.EntireRow.Copy to:
Range(Cells(c.Row, 1), Cells(c.Row, 7)).Copy


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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Searching for a word and then copy the whole row

Hi Kaj,

Am Thu, 28 Feb 2013 10:46:24 +0100 schrieb KP:

By the way, I would rather like to to copy from column B to column G instead
of
column A to G.


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
Range(Cells(c.Row, 2), Cells(c.Row, 7)).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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Searching for a word and then copy the whole row

Hi Claus,

Now everything works to my fully satisfaction.
I wish to thank you very much for your exellent and professionel help.

Best regards,
Kaj Pedersen



"Claus Busch" skrev i meddelelsen ...

Hi Kaj,

Am Thu, 28 Feb 2013 10:46:24 +0100 schrieb KP:

By the way, I would rather like to to copy from column B to column G
instead
of
column A to G.


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
Range(Cells(c.Row, 2), Cells(c.Row, 7)).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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
searching for a word(s) within a list Philippa Excel Discussion (Misc queries) 5 August 12th 08 07:30 PM
Searching and Then Copy Cell to word [email protected] Excel Programming 1 December 4th 07 11:53 AM
Searching: Many variations of one word J@Y Excel Programming 0 July 25th 07 02:56 PM
Searching using part of a word rather than whole word in vba Devitt[_3_] Excel Programming 1 October 12th 04 10:33 AM
Searching using part of a word rather than whole word in vba Devitt[_4_] Excel Programming 0 October 12th 04 10:32 AM


All times are GMT +1. The time now is 07:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"