У меня есть этот цикл, в котором я пытаюсь скопировать формулу в одну строку с одного листа на другой, а затем скопировать и вставить одну и ту же формулу во все строки первого листа.Цикл не копирует, вставляет формулу, и я думаю, что это часть копирования, где я отключен.
Кто-нибудь может мне помочь?
Вот что у меня есть.
Я ожидаю, что формула из выбранного столбца в первой строке будет скопирована во все строки в одном и том же столбце на другом листе.
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