Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2014, 07:41 AM
ksigcajun ksigcajun is offline Checking data in separate files Windows 7 64bit Checking data in separate files Office 2010 64bit
Advanced Beginner
Checking data in separate files
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default Checking data in separate files

I'm trying to create a macro that will compare data in two seperate files (spreadsheet A and B) and if it matches, return the data.



Here's the details. The macro will look at columns B, C, D, and E in spreadsheet A. If column B matches column C in spreadsheet B, then add columns C, D and E from spreadsheet A into columns J, K and L in spreadsheet B.

Any help would be greatly appreciated it.
Reply With Quote
  #2  
Old 05-19-2014, 08:05 PM
BobBridges's Avatar
BobBridges BobBridges is offline Checking data in separate files Windows 7 64bit Checking data in separate files Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

You can do this with a macro. But first let me ask: Why not do it with worksheet functions instead? A macro may be better, depending on your needs, but functions are often simpler, and also they keep the data updated rather than having to renew the match-and-add from time to time. So before we do a VBA program, are you sure you want to do it that way? If so, why?

(Hint: If the answer is "Yes, because I want to learn VBA", that's an acceptable reason.)
Reply With Quote
  #3  
Old 05-20-2014, 02:42 PM
macropod's Avatar
macropod macropod is offline Checking data in separate files Windows 7 32bit Checking data in separate files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Indeed it can be done easily enough using a combination of Excel's IF, INDEX & MATCH functions, without the need for a macro. Using the functions provides somewhat greater flexibility than a macro as they can update the output automatically according to changes in the inputs.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 05-22-2014, 04:50 AM
ScottA ScottA is offline Checking data in separate files Windows 7 64bit Checking data in separate files Office 2010 32bit
Advanced Beginner
 
Join Date: Apr 2014
Posts: 30
ScottA is on a distinguished road
Default

Pardon me for jumping in. I noticed something in the OP that made me question the replies.

Quote:
I'm trying to create a macro that will compare data in two seperate files (spreadsheet A and B) and if it matches, return the data.
I can understand using the functions on two worksheets with in the same workbook. That makes sense.

If as I'm reading it - two workbooks - you would need to use VBA wouldn't you? If that is not the case would you mind pointing me toward how to do this? I would like to learn this as well.
Reply With Quote
  #5  
Old 05-22-2014, 04:54 AM
macropod's Avatar
macropod macropod is offline Checking data in separate files Windows 7 32bit Checking data in separate files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You don't need VBA - it can be done with formulae that same as you might when comparing data on two different worksheets in the same workbook. Depending on the formulae used, you might need to have both workbooks open to do any updating.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 05-22-2014, 06:07 AM
BobBridges's Avatar
BobBridges BobBridges is offline Checking data in separate files Windows 7 64bit Checking data in separate files Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

He asked "how", Paul. Scott, try this:

1) Open two workbooks A and B.

2) Select an empty cell in A.

3) Type this sequence: "=<Ctrl-Tab><Down><Enter>".

Observe the formula that Excel just created; it shows the syntax you must use when pointing a formula to another open workbook.

(If you're not sure what just happened: "=" started the formula. <Ctrl-Tab> moved from workbook A to workbook B. <Down> moved the cursor down one row, pointing to the next cell (probably A2, but whatever). <Enter> completed the creation of the formula.)

Next:

4) Close workbook B.

Now look at the formula again; the syntax has changed a bit, showing what you must use to point to another closed workbook.

I usually find it easier to let Excel set the syntax, and then repeat it myself (modifying it and copying it down the column or whatever is appropriate), rather than typing it out myself and possibly forgetting a critical piece of the formula. And by the way, I've noticed that it's a little slower doing lookups to another workbook, and a lot slower if that workbook is closed. YMMV.
Reply With Quote
  #7  
Old 05-22-2014, 07:33 AM
ScottA ScottA is offline Checking data in separate files Windows 7 64bit Checking data in separate files Office 2010 32bit
Advanced Beginner
 
Join Date: Apr 2014
Posts: 30
ScottA is on a distinguished road
Default

Well I'll be dipped!

BobBridges - You were correct I was looking 'how' to do it. I tried your instructions an see exactly what you are talking about. Several warnings about security and connections to external data but works like a charm.

I'm really enjoying this forum. I've learned tons just reading!

Thanks for the clarification.

ksigcajun - sorry for jumping in the middle of your post!!
Reply With Quote
  #8  
Old 05-22-2014, 08:54 AM
BobBridges's Avatar
BobBridges BobBridges is offline Checking data in separate files Windows 7 64bit Checking data in separate files Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Ah, it's fun being appreciated . Remember what I said: In my experience, I've found that many VLOOKUP-or-whatevers to an external closed workbook is significantly slower than if it's open. I have one application where I write the VBA code to actually copy the table into a worksheet in the current workbook, every time it runs, to be sure of getting the latest info but without the drag on the lookups itself. Mind you, that one has a short lookup table but tens of thousands of rows doing lookups on it. If it were only a few hundred lookups it might not matter.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking data in separate files Displaying multiple columns of shared data in separate mpp files ggg Project 1 01-08-2013 08:08 AM
Checking data in separate files Can I use the filter function to separate letters into separate files? drhauser Mail Merge 2 12-14-2011 02:18 PM
Checking data in separate files Spell checking and saving files msword101 Word 1 10-08-2011 07:21 AM
Any easy way to separate a Word document into separate files? SamHelm Word 0 08-21-2010 05:29 AM
Checking for data corruption in Word mart12 Word 0 12-18-2008 03:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft