我正在尝试将公式粘贴到多个范围内。我实际上有一长串要粘贴的范围列表。有没有办法遍历此列表而无需为每个范围编写代码?我尝试将范围列表粘贴到一行中,对于一行来说太长了
Range('LCM-00 (2)'!$J$57:$Y$57).copy
Range('LCM-00 (2)'!$J$57:$Y$57,'LCM-00 (2)'!$J$54:$Y$54,'LCM-00 (2)'!$K$50:$Y$50,'LCM-00 (2)'!$K$47:$Y$47,'LCM-00 (2)'!$AB$57:$AQ$57,'LCM-00 (2)'!$AB$54:$AQ$54,'LCM-00 (2)'!$AC$50:$AQ$50,'LCM-00 (2)'!$AC$47:$AQ$47,'LCM-00 (2)'!$AT$57:$BI$57,'LCM-00 (2)'!$AT$54:$BI$54,'LCM-00 (2)'!$AU$50:$BI$50,'LCM-00 (2)'!$AU$47:$BI$47,'LCM-00 (2)'!$BL$57:$CA$57,'LCM-00 (2)'!$BL$54:$CA$54,'LCM-00 (2)'!$BM$50:$CA$50,'LCM-00 (2)'!$BM$47:$CA$47,'LCM-00 (2)'!$CD$57:$CS$57,'LCM-00 (2)'!$CD$54:$CS$54,'LCM-00 (2)'!$CE$50:$CS$51,'LCM-00 (2)'!$CE$47:$CS$47,'LCM-00 (2)'!$J$42:$Y$42,'LCM-00 (2)'!$K$35:$Y$35,'LCM-00 (2)'!$K$32:$Y$32,'LCM-00 (2)'!$AB$42:$AQ$42,'LCM-00 (2)'!$AB$39:$AQ$39,'LCM-00 (2)'!$AC$35:$AQ$35,'LCM-00 (2)'!$AC$32:$AQ$32,'LCM-00 (2)'!$AT$42:$BI$42,'LCM-00 (2)'!$AT$39:$BI$39,'LCM-00 (2)'!$AU$35:$BI$35,'LCM-00 (2)'!$AU$32:$BI$32,'LCM-00 (2)'!$BL$42:$CA$42,'LCM-00 (2)'!$BL$39:$CA$39,'LCM-00 (2)'!$BM$35:$CA$35,'LCM-00 (2)'!$BM$32:$CA$320,'LCM-00 (2)'!$CD$42:$CS$42,'LCM-00 (2)'!$CD$39:$CS$39,'LCM-00 (2)'!$CE$35:$CS$35,'LCM-00 (2)'!$CE$32:$CS$32,'LCM-00 (2)'!$J$28:$Y$28,'LCM-00 (2)'!$J$25:$Y$25,'LCM-00 (2)'!$K$21:$Y$21,'LCM-00 (2)'!$AB$28:$AQ$28,'LCM-00 (2)'!$AB$25:$AQ$25,'LCM-00 (2)'!$AC$21:$AQ$21,'LCM-00 (2)'!$AC$18:$AQ$18,'LCM-00 (2)'!$AT$28:$BI$28,'LCM-00 (2)'!$AT$25:$BI$25,'LCM-00 (2)'!$AU$21:$BI$21,'LCM-00 (2)'!$AU$18:$BI$18,'LCM-00 (2)'!$BL$28:$BI$28,'LCM-00 (2)'!$BL$25:$BI$25,'LCM-00 (2)'!$BM$21:$CA$21,'LCM-00 (2)'!$BM$18:$CA$18,'LCM-00 (2)'!$CD$28:$CS$28,'LCM-00 (2)'!$CD$25:$CS$25,'LCM-00 (2)'!$CE$21:$CS$21,'LCM-00 (2)'!$CE$18:$CS$18,'LCM-00 (2)'!$J$14:$Y$14,'LCM-00 (2)'!$J$11:$Y$11,'LCM-00 (2)'!$K$7:$Y$7,'LCM-00 (2)'!$K$4:$Y$4,'LCM-00 (2)'!$AB$14:$AQ$14,'LCM-00 (2)'!$AB$11:$AQ$11,'LCM-00 (2)'!$AC$7:$AQ$7,'LCM-00 (2)'!$AC$4:$AQ$4,'LCM-00 (2)'!$AT$14:$BI$14,'LCM-00 (2)'!$AT$11:$BI$11,'LCM-00 (2)'!$AU$7:$BI$7,'LCM-00 (2)'!$AU$4:$BI$4,'LCM-00 (2)'!$BL$14:$CA$14,'LCM-00 (2)'!$BL$11:$CA$11,'LCM-00 (2)'!$BM$7:$CA$7,'LCM-00 (2)'!$BM$4:$CA$4,'LCM-00 (2)'!$CD$14:CS$14,'LCM-00 (2)'!$CD$11:CS$11,'LCM-00 (2)'!$CE$7:CS$7,'LCM-00 (2)'!$CE$4:CS$44).select
range.xlpaste
不确定如何做到这一点。我是初学者。 TIA
答案 0 :(得分:1)
我希望我的目标是正确的 - 复制源范围并粘贴到同一工作簿中的多个范围。
A1:G1
具有从10
到70
A2
包含公式=A1+1
A3
包含公式=A1*2
下面的代码会将范围A2:A3
复制到多个范围,在文本字符串"B2:B3,C2:C3,D2:D3,E2:E3,F2:F3,G2:G3"
中以逗号分隔。您可以输入全范围文本,例如'Sheet2'!B2:B3,...
。
粘贴范围的代码:
Option Explicit
Sub PasteRanges()
Dim oRngSrc As Range, oItem As Variant, sPasteTo As String
Set oRngSrc = Range("A2:A3") ' Source Range to Copy From
sPasteTo = "B2:B3,C2:C3,D2:D3,E2:E3,F2:F3,G2:G3"
' This works:
oRngSrc.Copy Range(sPasteTo)
' If it complains about being too long, use below loop
For Each oItem In Split(sPasteTo, ",")
oRngSrc.Copy Range(oItem) ' Paste to oItem
Next
End Sub
<小时/> 就个人而言,我不推荐这种方法,但这就是你所要求的。