#1   Report Post  
Posted to microsoft.public.excel.misc
BPR
 
Posts: n/a
Default Merge two sheets

I have two sheets Sheet1 and Sheet2. In A1 in both sheets I have a key.

I need to:

1. When A1:A100 in Sheet2 find at match in A1:A100 in Sheet1 - copy
specific cells from Sheet2 to Sheet1 .
2. When a key in Sheet2 is not found in Sheet1 - copy the entire row in
Sheet2 to the end of Sheet1.

Can anyone give me a hint?


  #2   Report Post  
Posted to microsoft.public.excel.misc
tony h
 
Posts: n/a
Default Merge two sheets


try
Sub a()
Dim rng1 As Range
Dim rng2 As Range

Set rng1 = Worksheets(1).Range("A1")
Set rng2 = Worksheets(2).Range("A1")
Do Until rng1 = "" Or rng2 = ""
If rng1 < rng2 Then
Set rng1 = rng1.Offset(1)
ElseIf rng1 = rng2 Then
rng1.Offset(, 1) = rng2.Offset(, 1)
Set rng2 = rng2.Offset(1)
Else
rng1.EntireRow.Insert xlShiftDown
rng2.EntireRow.Copy rng1.Offset(-1).EntireRow
Set rng2 = rng2.Offset(1)
End If
Loop
MsgBox "done"
End Sub


regards


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=523042

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
How can I merge and purge two excel work sheets? Analia New Users to Excel 0 November 2nd 05 10:09 PM
How do I merge information from sheets on other files into the ma. jones021 Excel Worksheet Functions 0 April 20th 05 08:54 PM
How can I merge multiple sheets from different Excel files workbo. jones021 Excel Worksheet Functions 0 April 20th 05 08:48 PM
calculating excel spreadsheet files for pensions and life insurance (including age calculation sheets) RICHARD Excel Worksheet Functions 1 March 15th 05 05:49 PM
is there an easy way to merge data/information on several sheets . Robin Excel Discussion (Misc queries) 1 February 10th 05 03:12 PM


All times are GMT +1. The time now is 06:40 AM.

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"