Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to find, copy and paste

Hi,
I have two excel sheet. I am trying to copy a name from list of names in
sheet1, find it in sheet2 - copy the entire column (which contains the name
)and paste it into another column in sheet2. The macro works perfectly fine
until I hit a name that is not is in sheet2. When I put' On error goto....'it
works fine if it is after the Exit sub. It does not work otherwise.
This is what I want -When it hits a name that is not in sheet2, I want it to
go to the next name in sheet1 and continue with the process.

Any help would be appreciated!


Dim x As Range
Sheets("Sheet1").Select
Set x = Range("A1")
Do
x.Select
If ActiveCell.Value = "" Then
Exit Sub
End If
Application.CutCopyMode = False
Selection.Copy
Sheets("Req and Status").Select
Rows("1:1").Select
'On Error GoTo message

Selection.Find(What:=x, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Cut
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Sheets("Sheet1").Select
Set x = x.Offset(1)

Loop

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Macro to find, copy and paste

Your approach needs much work but you would be better served using FINDNEXT.
Look in vba help index for a good example.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"SeekAns" wrote in message
...
Hi,
I have two excel sheet. I am trying to copy a name from list of names in
sheet1, find it in sheet2 - copy the entire column (which contains the
name
)and paste it into another column in sheet2. The macro works perfectly
fine
until I hit a name that is not is in sheet2. When I put' On error
goto....'it
works fine if it is after the Exit sub. It does not work otherwise.
This is what I want -When it hits a name that is not in sheet2, I want it
to
go to the next name in sheet1 and continue with the process.

Any help would be appreciated!


Dim x As Range
Sheets("Sheet1").Select
Set x = Range("A1")
Do
x.Select
If ActiveCell.Value = "" Then
Exit Sub
End If
Application.CutCopyMode = False
Selection.Copy
Sheets("Req and Status").Select
Rows("1:1").Select
'On Error GoTo message

Selection.Find(What:=x, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Cut
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Sheets("Sheet1").Select
Set x = x.Offset(1)

Loop

End Sub


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
Macro - 2 Sheets - Find/Insert/Copy/Paste shorticake Excel Programming 0 March 12th 07 09:21 PM
Find/Copy/paste.. then Find/Paste - not working ... at all.... [email protected] Excel Programming 9 November 30th 06 08:49 PM
Macro to find copy "header" and paste RunsWithKnives Excel Discussion (Misc queries) 3 March 27th 06 05:55 AM
Macro to find, copy, and paste until value change Valerie Excel Worksheet Functions 4 January 26th 06 04:10 AM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM


All times are GMT +1. The time now is 12:34 PM.

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

About Us

"It's about Microsoft Excel"