【问题标题】:How to select a names from a column MS Excel 2007如何从 MS Excel 2007 列中选择名称
【发布时间】:2023-03-31 17:04:01
【问题描述】:

我有一个 Excel 文档,其中包含学生列表及其组名。我在同一个 Excel 文档中有另一张表,称为 cmets。在此表中,我希望列出各个团队的名称。

有 65 名学生和 14 个已定义的小组。

有没有一种方法可以选择 14 个组名,而无需重复?

单元格 B3-B67 有学生姓名。 单元格 C3-C67 有团队名称。针对每个学生输入团队名称。

我知道在 SQL 中我可以使用 select distinct(team_name) 之类的东西,但在 Excel 中,我该如何复制呢?

干杯, 阿尔克斯。

【问题讨论】:

标签: excel selection distinct


【解决方案1】:

您可以在 Excel 中使用 SQL。

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset 

''This is not necessarily the best way to get the workbook name
''that you need
strFile = Workbooks(1).FullName
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
    & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open strCon

''Note that HDR=Yes, so we can use Group, otherwise columns (fields)
''are named F1, F2 etc
''Pick one:
strSQL = "SELECT DISTINCT Group FROM DataTable" ''Named range
strSQL = "SELECT DISTINCT Group FROM [Sheet1$C3:C67]" ''Range

rs.Open strSQL, cn

Sheets("Sheet2").Cells(2, 1).CopyFromRecordset rs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 2012-04-27
    相关资源
    最近更新 更多