我有这个循环,在这里我尝试将一行中的公式从一张纸复制到另一张纸,然后将相同的公式复制粘贴到第一张纸的所有行中。循环不会复制粘贴公式,我认为这是我要复制的部分。
有人可以帮我吗?
这就是我所拥有的。
我希望第一列中所选列的公式将被复制到不同工作表中同一列中的所有行。
So i've managed to create the wanted code, by the following code (without the loop):
Dim startcell, startcell2, startcell3, startcell4, startcell5 As Range, lastrow, lastrow2, lastrow3, lastrow4, lastrow5 As Long, ws As Worksheet, pastebook, formula As Worksheet
Set formula = Sheet3
Set startcellformula = formula.Range("BI8")
Set startcellformula2 = formula.Range("BK8")
Set startcellformula3 = formula.Range("BO8")
Set startcellformula4 = formula.Range("BQ8")
Set startcellformula5 = formula.Range("BS8")
Set startcellformula6 = formula.Range("BU8")
Set startcellformula7 = formula.Range("BW8")
Set startcellformula8 = formula.Range("BY8")
Set startcellformula9 = formula.Range("CA8")
Set startcellformula10 = formula.Range("CC8")
Set startcellformula11 = formula.Range("CE8")
Set startcellformula12 = formula.Range("CG8")
Set startcellformula13 = formula.Range("CI8")
lastrow = ws.Cells(ws.Rows.Count, startcell.Column).End(xlUp).Row
startcellformula.Copy
pastebook.Range("BI8:BI" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("BK8:BK" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("BO8:BO" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("BQ8:BQ" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("BS8:BS" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("BU8:BU" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("BW8:BW" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("BY8:BY" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("CA8:CA" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("CC8:CC" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("CE8:CE" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("CG8:CG" & lastrow).PasteSpecial Paste:=xlFormulas
startcellformula.Copy
pastebook.Range("CI8:CI" & lastrow).PasteSpecial Paste:=xlFormulas
I've tried to work a bit more on the loop, and this where I am currently. I think the only steps left is some syntax.
'Copy formulas in every other Column between BH and CI
Set startcolumn = Range("BI8").Cells
Set Endcolumn = pastebook.Column("BI")
Set startcellformula = formula.Range(startcolumn)
For currCol = pastebook.Columns("BI").Column To pastebook.Columns("CI").Column Step 2
For startcolumn = pastebook.Columns(startcolumn).Column To currCol Step 2
For Endcolumn = pastebook.Columns(Endcolumn).Column To currCol Step 2
startcellformula.Copy
pastebook.Range(startcolumn, pastebook.Range(startcolumn & Endcolumn & lastrow)).PasteSpecial Paste:=xlFormulas
Next Endcolumn
Next startcolumn
Next currCol
答案 0 :(得分:0)
欢迎!
首先,此pastbook.currCol
应该是pastebook.currCol
。
第二,此currCol
将返回一个数字,因此此pastebook.currCol
并没有任何意义。
您需要一个pastebook.currCol
,而不是range
,它会提示您“对象不支持此方法。”。
不确定要使用哪个range
。这取决于您要实现的目标。