Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Match Cells & copy


Hi,

Does anyone have any suggestions for the following:

If Cell A2-Sheet 1 - Spreadsheet A matches
Cell B2 -Sheet 1-Spreadsheet B Then I would like to copy
the entire Sheet 1 from Spreadheet B to Sheet 2 on Spreadsheet A.

Any help would be greatly appreciated!


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=505357

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Match Cells & copy

Steve,

Change the names as appropriate, or use the correct object variables:

If Workbooks("Spreadsheet A.xls").Worksheets("Sheet 1").Range("A2").Value = _
Workbooks("Spreadsheet B.xls").Worksheets("Sheet 1").Range("B2").Value Then
Workbooks("Spreadsheet B.xls").Worksheets("Sheet 1").Cells.Copy _
Workbooks("Spreadsheet A.xls").Worksheets("Sheet 2").Cells
End If

HTH,
Bernie
MS Excel MVP


"STEVEB" wrote in message
...

Hi,

Does anyone have any suggestions for the following:

If Cell A2-Sheet 1 - Spreadsheet A matches
Cell B2 -Sheet 1-Spreadsheet B Then I would like to copy
the entire Sheet 1 from Spreadheet B to Sheet 2 on Spreadsheet A.

Any help would be greatly appreciated!


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=505357



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Match Cells & copy


Thanks Bernie!!! Everything worked great!!!

Would it be possible to expand the formula for:

If any cell in column A Sheet 1 Spreadsheet A matches
Cell B2 -in any of the sheets -Spreadsheet B Then I would like to copy

the entire Sheet (the match) from Spreadheet B to Sheet 2 on
Spreadsheet A.

Thanks again


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=505357

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Match Cells & copy

Steve,

Dim mySht As Worksheet

For Each mySht In Workbooks("Spreadsheet B.xls").Worksheets
If Not (IsError(Application.WorksheetFunction.Match( _
mySht.Range("B2").Value, Workbooks("Spreadsheet A.xls"). _
Worksheets("Sheet 1").Range("A:A"), False))) Then
mySht.Cells.Copy _
Workbooks("Spreadsheet A.xls").Worksheets("Sheet 2").Cells
MsgBox "Just copied " & mySht.Name
Exit Sub
End If
Next mySht

Note that this only copies one sheet. You could continue looping through by taking out the Exit Sub
line, but it would overwrite the existing data. You could make copies of Sheet 2 in that case - let
us know if you want to go that way.

HTH,
Bernie
MS Excel MVP


"STEVEB" wrote in message
...

Thanks Bernie!!! Everything worked great!!!

Would it be possible to expand the formula for:

If any cell in column A Sheet 1 Spreadsheet A matches
Cell B2 -in any of the sheets -Spreadsheet B Then I would like to copy

the entire Sheet (the match) from Spreadheet B to Sheet 2 on
Spreadsheet A.

Thanks again


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=505357



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Match Cells & copy


Hi Bernie,

Thanks again for your help, I appreciate it!

When I run the code, I get the following error:

Run Time error 1004 - Unable to get the match property of the worksheet
function class.

Do you know where i might be going wrong?

Thanks again


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=505357



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Match Cells & copy

Steve,

Remove the .WorksheetFunction - that created an error in one version of
Excel, IIRC.
(But not XP, which is what I tested the code in).

Bernie


"STEVEB" wrote in
message ...

Hi Bernie,

Thanks again for your help, I appreciate it!

When I run the code, I get the following error:

Run Time error 1004 - Unable to get the match property of the worksheet
function class.

Do you know where i might be going wrong?

Thanks again


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile:
http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=505357



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
Excel: match two cells in one sheet to two cells in another and return a third cells value Spence Excel Worksheet Functions 3 February 13th 11 05:33 AM
Find match between cells and copy data Kcope8302 Excel Worksheet Functions 7 September 18th 09 11:55 PM
Compare cells and copy columns after match Kcope8302 Excel Worksheet Functions 2 August 5th 09 05:37 PM
If match copy cells in visual basic. thomsonpa New Users to Excel 3 December 13th 07 05:14 PM
Copy a value from one sheet if two cells match Fuzzbucket Excel Discussion (Misc queries) 3 February 22nd 07 08:52 AM


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