[英]Excel merging two columns
I have two columns, each with slightly different list of countries 我有两列,每列的国家/地区列表略有不同
eg 例如
A B C
Japan Japan
US China
UK Brazil
India Canada
China Mexico
Brazil Germany
France
Peru
How do I "merge" the two columns so that I can have values that exist in either column A or B in column C, without repeating the values? 如何“合并”两列,以便我可以拥有存在于C列的A列或B列中的值,而无需重复这些值?
ie 即
A B C
Japan Japan Japan
US China US
UK Brazil UK
India Canada India
China Mexico China
Brazil Germany Brazil
France Canada
Peru Mexico
Germany
France
Peru
NOTE: I am currently using excel 2003 注意:我目前正在使用excel 2003
thanks a lot! 非常感谢!
EDIT: Here's my current attempts, in "exports and imports test" sheet, column G, I'm trying to VLOOKUP from the source of both columns A and D and "merge" it with an OR formula, and then sort it properly on the next column. 编辑:这是我目前的尝试,在“进出口测试”工作表的G列中,我试图从A列和D列的来源进行VLOOKUP并将其与OR公式“合并”,然后对它进行正确排序下一栏。 It's got an N/A error right now unfortunately...
不幸的是,现在有一个N / A错误...
http://wikisend.com/download/391826/Sample%20test.xls http://wikisend.com/download/391826/Sample%20test.xls
EDIT2: I tried using the macro posted below, while editing (by guessing) it to suit my needs, and the macro became this: EDIT2:我尝试使用下面发布的宏,同时根据自己的需要进行编辑(通过猜测),宏变成了:
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("G3").Select
ActiveSheet.Paste
Range("D3").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("G3").Select
Selection.End(xlDown).Select
Range("G30").Select
ActiveSheet.Paste
Range("G3").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
ActiveSheet.Range("$G$3:$G$60").RemoveDuplicates Columns:=1, Header:=xlNo
End Sub
And here is the result (column G): 结果如下(G列):
It didn't quite work (in that duplicates exist) and I got an “Object doesn't support support this property or method” error. 它不是很有效(因为存在重复项),并且出现“对象不支持支持此属性或方法”错误。
This is kind of a hack, but you could do this: 这是一种hack,但是您可以这样做:
=IF(A2=A1, "", A2)
, and drag down. =IF(A2=A1, "", A2)
放下。 This will print out the word only if it is different from the word above it. WHat about a macro like this (I'm assuming data are in columns A, B, and C starting at row 2 and without gaps): 关于这样的宏(我假设数据位于第2行开始且没有间隙的A,B和C列中):
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("C2").Select
ActiveSheet.Paste
Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("C2").Select
Selection.End(xlDown).Select
Range("C10").Select
ActiveSheet.Paste
Range("C2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
ActiveSheet.Range("$C$2:$C$16").RemoveDuplicates Columns:=1, Header:=xlNo
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.