Excel-使用不同工作表中某行的内容填充列标题

Excel-使用不同工作表中某行的内容填充列标题,excel,Excel,这是我的场景-我在工作表的a列中有一个客户列表-以及相关数据。。。我有另一张表,我想在其中创建一个矩阵…但有客户名单沿第1行 我希望将添加到第1页列中的新客户添加到第2页的行中 如何做到这一点?我不确定您的VBA功能水平,但在第一张工作表的代码隐藏中,您可以捕获Workhseet_更改事件 您可以检查更新后的单元格是否在A列中。如果在A列中,则可以将该值添加到第一行的第2页 以下是一些帮助您开始的代码: Private Sub Worksheet_Change(ByVal Target As R

这是我的场景-我在工作表的a列中有一个客户列表-以及相关数据。。。我有另一张表,我想在其中创建一个矩阵…但有客户名单沿第1行

我希望将添加到第1页列中的新客户添加到第2页的行中


如何做到这一点?

我不确定您的VBA功能水平,但在第一张工作表的代码隐藏中,您可以捕获Workhseet_更改事件

您可以检查更新后的单元格是否在A列中。如果在A列中,则可以将该值添加到第一行的第2页

以下是一些帮助您开始的代码:

Private Sub Worksheet_Change(ByVal Target As Range)

    'check to make sure the updated cell (Target) is in column 1 (column A)
    If Target.Column = 1 Then addToSheet2 (Target.Value2)

End Sub

Private Sub addToSheet2(ByVal newValue As Variant)

    Dim ws As Worksheet
    Dim columnCount As Integer
    Dim nextColumn As Integer

    On Error GoTo errTrap

    Set ws = ThisWorkbook.Sheets(2) 'probably want to use the sheet name, instead of the index

    'probably a good idea to check if it already exists in row 1 of sheet 2

    'get the number of columns used in sheet 2
    columnCount = ws.UsedRange.Columns.Count

    'this may be overkill, but if you are starting from scratch, columnCount will be 1 even if
    'there is no data in sheet 2 row 1
    If columnCount = 1 And ws.Range("A1").Value2 = vbNullString Then
        nextColumn = columnCount
    Else
        nextColumn = columnCount + 1
    End If

    ws.Cells(1, nextColumn).Value2 = newValue

errTrap:
    Set ws = Nothing

End Sub

复制>>PasteSpecial>>TransposeTim-这就是我所处的位置-但是,通过单元格链接,我想让它超越“傻瓜”的基础。。。工作效率更高,确保我不会忘记或弄乱我的矩阵,这些矩阵是随着时间的推移创建的。JMax-Ive“尝试”复制粘贴或手动输入。。。这就是为什么我;我问“我该怎么做”——因为我不知道从哪里开始,除了理论上可以做到之外。