【问题标题】:How to auto-populate a names list to one sheet based on data in another sheet in Excel for Mac 2016如何根据 Excel for Mac 2016 中另一张表中的数据将名称列表自动填充到一张表中
【发布时间】:2017-11-29 20:35:18
【问题描述】:

我搜索了似乎在回答问题的其他页面。我曾尝试在工作表之间使用 if-then 公式来执行此操作,但它不适用于多个单元格/列。我想不通。

我在某处看到有人建议查询(但那是在 Google 中使用的,在 Excel 中不起作用)。关于如何最好地做到这一点的任何建议?

我正在尝试在 Excel 中创建一个顾问数据库。我们在项目上使用顾问,各种顾问执行 X 份工作。

表 1 将是包含以下数据的主列表

A1 - 公司名称

B1 - 专业 1

C1 - 专长 2

D1 - 专业 3

(等等 - 最多可能有 10 个专业),然后

L1 - 主要联系人

M1 - 电子邮件 1

N1 - 电子邮件 2

O1 - 电子邮件 3

P1 - 电子邮件 4

第一季度 - 以前的项目

等等(可能有手机号码等添加)

表 2 及以后将根据专业进行填充。

假设表 2 称为建筑师。如果其中一项专业与“建筑师”匹配,我希望它在建筑师表(表 2)上为我提供以下信息:

A1 公司名称

B1 主要联系人

C1 邮箱1

D1 电子邮件2

E1 邮箱3

F1 电子邮件4

G1 以前的项目

有人可以帮我弄清楚如何自动填充吗?随着主工作表的变化,我不必经常更新其他工作表。

【问题讨论】:

  • 欢迎来到 SO,我找不到明确的问题(这不是“我的代码”网站),你能修改你的帖子并定义一个要解决的问题吗?请阅读>How to Ask
  • 完成。不是在寻找免费编码。寻找具体的建议。
  • 您是否有每个“公司”的“主列表”表,或者“A1”是否表示“第 1 行”等?
  • 该死...编辑。对此感到抱歉。
  • 这听起来最好用 MS Access 代替

标签: excel vba macos excel-formula excel-2016


【解决方案1】:

潜在的“查询”工作表Worksheet_Change 事件(即此代码应粘贴到您用于“查询”的实际工作表的代码模块中):

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
    On Error GoTo ReEnableEvents
    Application.EnableEvents = False
    Dim lastRow As Long
    Dim r As Long
    Dim c As Long
    Dim newRow As Long
    Dim Speciality As String
    Speciality = Range("A1").Value
    'clear existing data
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    If lastRow > 2 Then ' Assume headings are on row 2
        Rows("3:" & lastRow).ClearContents
    End If
    'find new data
    newRow = 2
    With Worksheets("MasterList")
        For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
            For c = 2 To 11 ' loop through the speciality columns
                If .Cells(r, c).Value = Speciality Then
                    newRow = newRow + 1
                    Cells(newRow, "A").Value = .Cells(r, "A").Value
                    Cells(newRow, "B").Value = .Cells(r, "L").Value
                    Cells(newRow, "C").Value = .Cells(r, "M").Value
                    Cells(newRow, "D").Value = .Cells(r, "N").Value
                    Cells(newRow, "E").Value = .Cells(r, "O").Value
                    Cells(newRow, "F").Value = .Cells(r, "P").Value
                    Cells(newRow, "G").Value = .Cells(r, "Q").Value                        
                    Exit For
                End If
            Next
        Next
    End With
ReEnableEvents:
    Application.EnableEvents = True
End Sub

这假定“查询”表的单元格 A1 是您要查找的值(即“专业”),该表的第 2 行将有标题,并且第 3 行以后将填充结果。

我没有测试过,但是应该和你需要的差不多。

【讨论】:

  • 注意:我不知道所有代码在 Mac 版本的 Excel 上是否有效。它看起来相当基本,所以我不认为你会遇到任何问题。
猜你喜欢
  • 2016-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-10
相关资源
最近更新 更多