Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default merge sheets based on common id with VBA

Hi
I need to loop throu Sheet1, read id in col A and mydata in col B - find the
matching id in Sheet2 col A and copy mydata into col C of Sheet2.
Sheet1 has few rows, Sheet2 many
Any help much appreciated!
Ulf




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default merge sheets based on common id with VBA

Use the Vlookup worksheet function in column C of Sheet2. You can replace
the formula with its results after.

With worksheets("Sheet2").Range("C2:C500")
.Formula = "=Vlookup(A2,Sheet1!A:B,2,False)"
.formula = .Value
End With

--
Regards,
Tom Ogilvy


"ulfb" wrote:

Hi
I need to loop throu Sheet1, read id in col A and mydata in col B - find the
matching id in Sheet2 col A and copy mydata into col C of Sheet2.
Sheet1 has few rows, Sheet2 many
Any help much appreciated!
Ulf




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default merge sheets based on common id with VBA

Thank you Tom
Unfortunately I can't make it work, results in: #NAME?. What am I doing wrong
/ulf

Sub MergeClubMemb()
' add member data for some clubs to main sheet with all clubs

Dim WSmain As Worksheet
Dim WSdata As Worksheet

Set WSmain = Sheet40 ' all clubs, id in col B
Set WSdata = Sheet42 ' some clubs with member data, id in col A, data
in B

With WSmain.Range("H2:H500")
.Formula = "=Vlookup(WSdata.Range(A:B),2,False)"
.Formula = .Value
End With

End Sub



"Tom Ogilvy" wrote:

Use the Vlookup worksheet function in column C of Sheet2. You can replace
the formula with its results after.

With worksheets("Sheet2").Range("C2:C500")
.Formula = "=Vlookup(A2,Sheet1!A:B,2,False)"
.formula = .Value
End With

--
Regards,
Tom Ogilvy


"ulfb" wrote:

Hi
I need to loop throu Sheet1, read id in col A and mydata in col B - find the
matching id in Sheet2 col A and copy mydata into col C of Sheet2.
Sheet1 has few rows, Sheet2 many
Any help much appreciated!
Ulf




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default merge sheets based on common id with VBA

You are mixing VBA inside your Excel formula. The formula puts in vlookup
literally how you have written it.

A. Excel doesn't know what WSdata.Range(A:B) is - that is you #Name error
you should have Sheet42!A:B instead.
B. You left out the first argument to vlookup.

--
Regards,
Tom Ogilvy


"ulfb" wrote in message
...
Thank you Tom
Unfortunately I can't make it work, results in: #NAME?. What am I doing
wrong
/ulf

Sub MergeClubMemb()
' add member data for some clubs to main sheet with all clubs

Dim WSmain As Worksheet
Dim WSdata As Worksheet

Set WSmain = Sheet40 ' all clubs, id in col B
Set WSdata = Sheet42 ' some clubs with member data, id in col A,
data
in B

With WSmain.Range("H2:H500")
.Formula = "=Vlookup(WSdata.Range(A:B),2,False)"
.Formula = .Value
End With

End Sub



"Tom Ogilvy" wrote:

Use the Vlookup worksheet function in column C of Sheet2. You can
replace
the formula with its results after.

With worksheets("Sheet2").Range("C2:C500")
.Formula = "=Vlookup(A2,Sheet1!A:B,2,False)"
.formula = .Value
End With

--
Regards,
Tom Ogilvy


"ulfb" wrote:

Hi
I need to loop throu Sheet1, read id in col A and mydata in col B -
find the
matching id in Sheet2 col A and copy mydata into col C of Sheet2.
Sheet1 has few rows, Sheet2 many
Any help much appreciated!
Ulf






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
In Excel 07, how do I merge two sprdshts with a common column? aleve21 Excel Worksheet Functions 1 May 6th 09 05:32 PM
Combining two ranges based on common a common value ahmed[_3_] Excel Discussion (Misc queries) 5 April 18th 09 05:04 PM
How do I merge info. from 2 sheets using common numbers in Excel? Angela Excel Worksheet Functions 1 June 7th 07 10:20 PM
merge worksheets which share a common column? Neha Excel Worksheet Functions 1 February 20th 07 02:50 PM
Excel: how to merge data from 2 workbooks with 1 col. in common? Cesare Excel Discussion (Misc queries) 2 June 24th 05 11:14 PM


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

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

About Us

"It's about Microsoft Excel"