Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 151
Default match some fields & write new file

Hi everyone,
I have 2 sheets in a workbook.
Sheet1 has 14 fields and first 4 are unique
Sheet2 has 21 fields and first 4 are unique (say equal to sheet1)
Now, How to pick each row from sheet1 (4 fields) find their equals in sheet2
collect those equal rows and put in a new workbook and close with a new name.

Any help on this please (code or links).


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default match some fields & write new file

This is the kind of thing. You'll want to amend it (unless you're happy to
wait for a couple of hours!) as it currently compares all empty cells too.
It also pastes to a sheet in the same workbook (sheet3) rather than a
workbook:

Sub PasteMatches()
Dim cell1 As Range
Dim cell2 As Range
For Each cell1 In Worksheets("Sheet1").Columns(1).Cells
For Each cell2 In Worksheets("Sheet2").Columns(1).Cells
If cell2.Value & cell2.Offset(0, 1).Value & cell2.Offset(0, 2).Value
& cell2.Offset(0, 3).Value = cell1.Value & cell1.Offset(0, 1).Value &
cell1.Offset(0, 2).Value & cell1.Offset(0, 3).Value Then
cell2.EntireRow.Copy
Worksheets("Sheet3").Activate
Range("A1").CurrentRegion.Select
Selection.Offset(Selection.Rows.Count).Resize(1, 1).Select
ActiveSheet.Paste
End If
Next cell2
Next cell1
End Sub

"Eddy Stan" wrote:

Hi everyone,
I have 2 sheets in a workbook.
Sheet1 has 14 fields and first 4 are unique
Sheet2 has 21 fields and first 4 are unique (say equal to sheet1)
Now, How to pick each row from sheet1 (4 fields) find their equals in sheet2
collect those equal rows and put in a new workbook and close with a new name.

Any help on this please (code or links).


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 151
Default match some fields & write new file

boss it didn't work. each time it gives different error.
and it did write even one matching in sheet3.
Can you try please.
Further the code runs more up to 4 min for 5 rows in sheet1 and 1000 rows in
sheet2

"Martin" wrote:

This is the kind of thing. You'll want to amend it (unless you're happy to
wait for a couple of hours!) as it currently compares all empty cells too.
It also pastes to a sheet in the same workbook (sheet3) rather than a
workbook:

Sub PasteMatches()
Dim cell1 As Range
Dim cell2 As Range
For Each cell1 In Worksheets("Sheet1").Columns(1).Cells
For Each cell2 In Worksheets("Sheet2").Columns(1).Cells
If cell2.Value & cell2.Offset(0, 1).Value & cell2.Offset(0, 2).Value
& cell2.Offset(0, 3).Value = cell1.Value & cell1.Offset(0, 1).Value &
cell1.Offset(0, 2).Value & cell1.Offset(0, 3).Value Then
cell2.EntireRow.Copy
Worksheets("Sheet3").Activate
Range("A1").CurrentRegion.Select
Selection.Offset(Selection.Rows.Count).Resize(1, 1).Select
ActiveSheet.Paste
End If
Next cell2
Next cell1
End Sub

"Eddy Stan" wrote:

Hi everyone,
I have 2 sheets in a workbook.
Sheet1 has 14 fields and first 4 are unique
Sheet2 has 21 fields and first 4 are unique (say equal to sheet1)
Now, How to pick each row from sheet1 (4 fields) find their equals in sheet2
collect those equal rows and put in a new workbook and close with a new name.

Any help on this please (code or links).


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 151
Default match some fields & write new file

Hi Martin,
your code is not giving error or not giving answer to my problem.
Can you try with your own example and send me your sample excel sheet to


Thanks for your try...

"Martin" wrote:

This is the kind of thing. You'll want to amend it (unless you're happy to
wait for a couple of hours!) as it currently compares all empty cells too.
It also pastes to a sheet in the same workbook (sheet3) rather than a
workbook:

Sub PasteMatches()
Dim cell1 As Range
Dim cell2 As Range
For Each cell1 In Worksheets("Sheet1").Columns(1).Cells
For Each cell2 In Worksheets("Sheet2").Columns(1).Cells
If cell2.Value & cell2.Offset(0, 1).Value & cell2.Offset(0, 2).Value
& cell2.Offset(0, 3).Value = cell1.Value & cell1.Offset(0, 1).Value &
cell1.Offset(0, 2).Value & cell1.Offset(0, 3).Value Then
cell2.EntireRow.Copy
Worksheets("Sheet3").Activate
Range("A1").CurrentRegion.Select
Selection.Offset(Selection.Rows.Count).Resize(1, 1).Select
ActiveSheet.Paste
End If
Next cell2
Next cell1
End Sub

"Eddy Stan" wrote:

Hi everyone,
I have 2 sheets in a workbook.
Sheet1 has 14 fields and first 4 are unique
Sheet2 has 21 fields and first 4 are unique (say equal to sheet1)
Now, How to pick each row from sheet1 (4 fields) find their equals in sheet2
collect those equal rows and put in a new workbook and close with a new name.

Any help on this please (code or links).


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 151
Default match some fields & write new file

Hello - somebody talk to me, I am desperate for excel code.

"Eddy Stan" wrote:

Hi Martin,
your code is not giving error or not giving answer to my problem.
Can you try with your own example and send me your sample excel sheet to


Thanks for your try...

"Martin" wrote:

This is the kind of thing. You'll want to amend it (unless you're happy to
wait for a couple of hours!) as it currently compares all empty cells too.
It also pastes to a sheet in the same workbook (sheet3) rather than a
workbook:

Sub PasteMatches()
Dim cell1 As Range
Dim cell2 As Range
For Each cell1 In Worksheets("Sheet1").Columns(1).Cells
For Each cell2 In Worksheets("Sheet2").Columns(1).Cells
If cell2.Value & cell2.Offset(0, 1).Value & cell2.Offset(0, 2).Value
& cell2.Offset(0, 3).Value = cell1.Value & cell1.Offset(0, 1).Value &
cell1.Offset(0, 2).Value & cell1.Offset(0, 3).Value Then
cell2.EntireRow.Copy
Worksheets("Sheet3").Activate
Range("A1").CurrentRegion.Select
Selection.Offset(Selection.Rows.Count).Resize(1, 1).Select
ActiveSheet.Paste
End If
Next cell2
Next cell1
End Sub

"Eddy Stan" wrote:

Hi everyone,
I have 2 sheets in a workbook.
Sheet1 has 14 fields and first 4 are unique
Sheet2 has 21 fields and first 4 are unique (say equal to sheet1)
Now, How to pick each row from sheet1 (4 fields) find their equals in sheet2
collect those equal rows and put in a new workbook and close with a new name.

Any help on this please (code or links).




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default match some fields & write new file

Eddy,

I have just emailed you a workbook l am developing as ad Excel Add-In
that will do what you want. However the 2 lists will need to be copied
side by side to another sheet.

Regards

Michael beckinsale

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
Match multiple fields Belinda7237 Excel Worksheet Functions 5 October 21st 08 05:18 PM
Match Corresponding Rows and Add Fields Together Dan Excel Worksheet Functions 2 April 2nd 08 02:45 PM
Trying to match certain fields from 1 workbook to another AngelaD Excel Discussion (Misc queries) 0 January 15th 07 08:02 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
Trying to match fields and return a value Jamie Excel Programming 1 February 15th 05 02:45 AM


All times are GMT +1. The time now is 02:05 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"