Excel工作表之间的自动填充

时间:2015-03-19 11:57:19

标签: excel

我有一个带有~300个类似工作表的excel文档和一个带有名称列表的工作表。这300个工作表中的每一个都有一个特定的单元格,我需要从列表中填写一个名称。列表和工作表的顺序相同(例如,sheet1需要List!C1中的名称,List中的sheet2,C2等)。我查看了VLOOKUP,但我没有使用任何参考数据。

1 个答案:

答案 0 :(得分:1)

我认为对于类似的任务,你需要使用像这样的VBA宏:

Sub DataFromList()

Dim nameSht As String: nameSht = "List"
Dim shtList As Worksheet
Set shtList = ThisWorkbook.Worksheets(nameSht)

Dim columnWithData As String: columnWithData = "C"
Dim n%: n = 0 ' start from 1 row (0 + 1)

' specific cell where you need to fill a name from the list
Dim addressForData As String: addressForData = "B2"

For Each sht In ThisWorkbook.Worksheets
    If sht.Name <> nameSht Then
        n = n + 1
        sht.Range(addressForData).Formula = "=" & nameSht & "!" & columnWithData & n
    End If
Next sht
End Sub

当然,只有当“特定单元格”的地址在所有表格中相同时才有可能