按国家/地区从工作表中提取数据

Pulling data out of an worksheet by country

我的 excel sheet 中有很多人,我想用 excel 编码按国家/地区拆分他们,这是我的数据示例:

Country | Name
UK      | Tom
Austria | Bobsky
UK      | Ralf
Germany | Badolf
Germany | Schwartz
UK      | Andy

那么是否可以将在英国的人分成我传播的不同部分sheet? 我已经试过了 INDEX(B1:B6, MATCH("UK", A1:A6,0)) - 如果匹配函数 returns 没有结果,则此 returns 重复行 我也尝试了很多东西 if(VLOOKUP(etc etc) = "UK"..... 而且我发现这也不起作用。我认为这将是 excel 无需过滤 + 复制和粘贴或使用 VBA 即可简单完成的事情,但这并不容易。

不用浪费时间起草复杂的Excel公式:

选项 1

使用数据透视表,其中您将“国家/地区”列用作过滤器

选项 2

像这样在每个工作表上使用 Microsoft Query Data->From Other Sources->Microsoft Query

SELECT * FROM [Sheet1$] WHERE Country = 'UK' ORDER BY NAME

这对于几千行数据是可行的。如果您的 'huge amount of people' 远不止于此,高级过滤器或枢轴 table 是更可行的解决方案。

在 D3 中使用 UK 在 E3 中使用以下内容。

=IFERROR(INDEX($B:$B99, SMALL(INDEX(ROW(:95)+($A:$A96<>D3)*1E+99, , ), ROW(1:1))), "")

根据需要填写。

Sub processData()
'I have workout for only UK 
'this macro copies records of UK people from Sheet1 to Sheet2
lastrows = Worksheets("Sheet1").Cells(Rows.count, 1).End(xlUp).Row
count = 1
For x = 2 To lastrows
    If (Worksheets("Sheet1").Cells(x, 1) = "UK") Then
        Worksheets("Sheet2").Cells(count, 1) = Worksheets("Sheet1").Cells(x, 1)
        Worksheets("Sheet2").Cells(count, 2) = Worksheets("Sheet1").Cells(x, 2)
        count = count + 1
    End If
Next x
MsgBox "Task finished"
End Sub