我如何可以并排放置一些桌子?

时间:2019-06-14 20:47:44

标签: excel

我想并排放置许多表格,如下例所示:

表有1

var 1   var 2   var 3
A       1,12    2,8
B       3,6     5,49
C       2,22    2,45
D       7,9     0,56
E       3,45    1,21
F       9,8     2,65
G       4,34    8,8

表有2

var 1   var 4   var 5 
A        4,99    3,4
B        5,99    3,8
C        6,99    4,2
D        7,99    4,6
E        8,99    5
F        9,99    5,4
G        10,99   5,8

表旺旺3

var 1       var 2   var 3   var 4   var 5 
A           1,12    2,8     4,99    3,4
B           3,6     5,49    5,99    3,8
C           2,22    2,45    6,99    4,2
D           7,9     0,56    7,99    4,6
E           3,45    1,21    8,99    5,0
F            9,8    2,65    9,99    5,4
G           4,34    8,8     10,99   5,8

我认为我必须参加会议。

但是我不知道该怎么办。

2 个答案:

答案 0 :(得分:1)

只需在表1中为var 4和5添加列并使用vlookup。

答案 1 :(得分:0)

正如其他人所建议的,VLOOKUPINDEX/MATCH会很好地满足您的需求。但是,如果需要使用VBA解决方案,请根据帖子的初始标签,看看是否有帮助(代码注释中的更多详细信息):

Sub joinTables()

Dim wsDst As Worksheet: Set wsDst = ActiveWorkbook.Sheets("Sheet Name") '<-- declare and allocate sheet name

Dim arrTable_One As Variant: arrTable_One = Range("TableHave1").Columns(1) 'declare and allocate the first column from the first table to an array
Dim arrTable_Two As Variant: arrTable_Two = Range("TableHave2") 'declare and allocate the second table to an array

Dim arrTable_Three As Variant
arrTable_Three = Range("TableHave1").Offset(-1).Resize(Range("TableHave1").Rows.Count + 1, Range("TableHave1").Columns.Count + 2) 'Get the first table to an array, including headings and extra 2 columns

Dim R1 As Long, R2 As Long

For R1 = LBound(arrTable_One) To UBound(arrTable_One) 'for each row in first table
    For R2 = LBound(arrTable_Two) To UBound(arrTable_Two) 'for each row in second table
        If arrTable_One(R1, 1) = arrTable_Two(R2, 1) Then 'if they match
            arrTable_Three(R1 + 1, 4) = arrTable_Two(R2, 2) 'allocate the data in the same row, column 4
            arrTable_Three(R1 + 1, 5) = arrTable_Two(R2, 3) 'allocate the data in the same row, column 5
            Exit For 'already had a match, check next one
        End If
    Next R2
Next R1

Dim rngWant3 As Range
With wsDst
    Set rngWant3 = .Range(.Cells(1, 1), .Cells(UBound(arrTable_Three), UBound(arrTable_Three, 2))) 'set the range to hold back the data
    rngWant3 = arrTable_Three 'allocate the data into the desired range
    .ListObjects.Add(xlSrcRange, rngWant3, , xlYes).Name = "TableWant3" 'create a table over that range
End With
End Sub