我编写了以下代码,根据我的“Master”工作表B中有多少行具有名称,在我的工作簿中创建一个附加工作表的变量#。此宏还复制了B列中的各种名称。掌握并粘贴在附加纸张上的单元格A7中。我遇到问题的最后一步是将以下单元格从主工作表复制到新创建的工作表:
主控:C7,E7,F7,J7,R7,S7,U7,V7,W7,X7,Y7,AA7
创建的表格:A62,D21,D29,D23,D25,D36,I21,I29,I23,I25,I36,D45
非常感谢任何想法。
Sub CreateAddtlSheets()
Dim ListSh As Worksheet, BaseSh As Worksheet
Dim NewSh As Worksheet
Dim ListOfNames As Range, LRow As Long, Cell As Range
With ThisWorkbook
Set ListSh = .Sheets("Master")
Set BaseSh = .Sheets("Stmt")
End With
LRow = ListSh.Cells(Rows.Count, "B").End(xlUp).Row
Set ListOfNames = ListSh.Range("B7:B" & LRow)
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
For Each Cell In ListOfNames
BaseSh.Copy After:=Sheets(Sheets.Count)
Set NewSh = ActiveSheet
With NewSh
On Error GoTo 0
.Range("A7") = Cell.Value
.Calculate
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
End With
Next Cell
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
BaseSh.Activate '--Select Base.
Sheets("Setup").Select
End Sub
答案 0 :(得分:0)
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
什么也没做,因为它复制然后粘贴到同一个空间。来自findwindow的评论是正确的,只需按照您的方式设置单元格值
.Range("A7") = Cell.Value
或者我们错过了什么?