我遇到以下vba脚本的问题。 我想将一些单元格从一张纸复制到另一张纸。 根据名称选择第一张纸。根据第一张纸中的单元格B1选择要粘贴单元格的纸张。 我使用以下代码:
Dim ws as Worksheet
Dim LR3 as Long
Dim LR4 as Long
Dim LR5 as Long
Dim ws3 as Worksheet
For Each ws In ActiveWorkbook.Worksheets
If Not ws.Name Like "BC-*" Then
LR3 = ws.Cells(Rows.Count, 1).End(xlUp).Row
ws.Range("E" & LR3 + 1).Formula = "=SUM(E4:E" & LR3 & ")"
Dim i As Long, n As Long
n = ws.Cells(Rows.Count, 1).End(xlUp).Row
With ws.Range("S1")
.Formula = "=myJoin(A4:A" & n & ","""")"
.Value = .Value
End With
LR4 = ws.Cells(Rows.Count, 6).End(xlUp).Row
ws.Range("F4:F" & LR4).Copy
ws.Range("M4:M" & LR4).PasteSpecial Paste:=xlPasteValues
ws.Range("M4:M" & LR4).RemoveDuplicates Columns:=1, Header:=xlNo
LR5 = ws.Cells(Rows.Count, 13).End(xlUp).Row
ws.Range("M4:M" & LR4).Cut
Set ws3 = ws.Range("B1").Value
ws3.Range("A30").PasteSpecial xlPasteValues
答案 0 :(得分:0)
您需要使用:
Set ws3 = ActiveWorkbook.Worksheets(ws.Range("B1").Value)
例如,。如果需要,请调整工作簿。