我正在尝试使用名单列表运行循环。每个名称都会更改一个单元格的值,然后更改另一个工作表上的值的主机。
问题在于,当我运行循环时,列表值上的最后一个单元格将替换所有其他值。
Sub MasterBrandList()
Dim ChangingBrand As String, PreVBAData As Worksheet, VBAData As Worksheet, lr As Long, rng As Range
For Each c In ThisWorkbook.Worksheets("Pivots_allbrands").Range("A2:A10").Cells
ThisWorkbook.Worksheets("Pivots_allbrands").Range("M1").Value = c.Value
Set PreVBAData = Sheets("PreVBAData")
Set VBAData = Sheets("VBAData")
lr = PreVBAData.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = PreVBAData.Range("A2:A" & lr)
rng.EntireRow.Copy VBAData.Cells(Rows.Count, 1).End(xlUp)(2)
Next
End Sub
答案 0 :(得分:0)
我认为问题是因为你试图在这里复制公式:
rng.EntireRow.Copy VBAData.Cells(Rows.Count, 1).End(xlUp)(2)
将此行替换为以下内容:
rng.EntireRow.Copy
Set r = VBAData.Cells(Rows.Count, 1).End(xlUp)(2)
r.PasteSpecial xlPasteValues