![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Location: Chicago, USA
Posts: 174
|
In my column A, I have "Names", in B it has "March Sales Results".
On sheet 2, I have "Names", in B column "April Sales". I like to have one Column of "Names" in column A, in column B "Mar Sales, in column C "apr Sales". Please advise, how to do it. Thank you |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
|
Are there any differences between the Names on Sheet1 and Sheet2? If not, will that always be the case?
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Location: Chicago, USA
Posts: 174
|
Thank you for your interest.
Yes, the list of Names will have some different names eg: First List of Name may have " John, Gene, Bob" and the second list of names may be " Bill, John, Amy" |
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
|
Quote:
...this SQL... SELECT Table1.Names, Table2.`Mar Sales`, Table1.`April Sales` FROM {oj Table1 Table1 LEFT OUTER JOIN Table2 Table2 ON Table1.Names = Table2.Names} UNION SELECT Table2.Names, Table2.`Mar Sales`, Table1.`April Sales` FROM {oj Table2 Table2 LEFT OUTER JOIN Table1 Table1 ON Table1.Names = Table2.Names} ...produces... {"Names","Mar Sales","April Sales" ;"Amy",25,0 ;"Bill",5,0 ;"Bob",0,30 ;"Gene",0,20 ;"John",15,10} ...from... {"Names","April Sales" ;"John",10 ;"Gene",20 ;"Bob",30} ...and... {"Names","Mar Sales" ;"Bill",5 ;"John",15 ;"Amy",25} [ This Message was edited by: Mark W. on 2002-05-07 15:35 ] |
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Mar 2002
Location: Chicago, USA
Posts: 174
|
Thank you for your advice..
When I try to run SQL, it gives an error message that Missiing LEFT or RIGHT before Sheet1$ Am I doing something wrong? |
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
|
I'm not quite sure what you mean by "...When I try to run SQL...". Are you creating named ranges for your 2 lists (Table1 and Table2 in my example) and using the Data | Get External Data | Create New Query... menu command?
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Mar 2002
Location: Chicago, USA
Posts: 174
|
Thank you once again..
I tried again your SQL, it WORKED PERFECT!!! Just out of Curosity, if I have 6 tables instead of 2 tables and each tables have 10 columns. How I can do? (The concept is still the same to Combine Name columns into one Column) Thank you. |
|
|
|
|
|
#8 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
|
Quote:
SELECT T1.Col1, T1.Col2, T1.Col3... FROM Table1 T1 UNION ALL SELECT T2.Col1, T2.Col2, T2.Col3... FROM Table2 T2 UNION ALL ... UNION ALL SELECT T6.Col1, T6.Col2, T6.Col3... FROM Table6 T6; ...And, then source a PivotTable from the resultant data range. |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|