早上好,
提前感谢您提供的任何帮助。我编写了一个代码,使用工作表“Y”中b6中的参考编号来计算工作表x上基于该数字的列数,并启动公式6行。然后,它将公式粘贴到第六行的适当单元格中,并带有变量列。
以下是代码:
Sub testingme4()
Dim myvalue As Double, lastrow As Long
myvalue = Worksheets("x").Cells(6, 2).Value
Worksheets("y").Cells(6, (myvalue) + 21).Cells.FormulaR1C1 = "formula"
End Sub
这对我来说很有效。
然而,当我试图将它粘贴到整行时,它会变得不稳定。
我补充说:
Dim lastrow as long
lastrow = Worksheets("y").Cells(Rows.Count, 1).End(xlUp).Row
哪个也可以工作并计算正确的行数(使用'MsgBox'最后一行数据:“& lastrow& vbCrLf来验证)
最后一部分是我需要循环公式,直到它到达我在第一个语句中选择的列的最后一行。
我试过了:
Dim paster as long,
For paster = Worksheets("x").Cells(6, (myvalue) + 21) To lastrow
Cells.FormulaR1C1 = "formula"
Next paster
这不断给我一个内存不足的错误。
再次感谢您的帮助。
EP
答案 0 :(得分:0)
没有测试过,但它应该有用。
Sub testingme4()
Dim myvalue As Double, lastrow As Long
Dim paster As String
lastrow = Worksheets("y").Cells(Rows.Count, 1).End(xlUp).Row
myvalue = Worksheets("x").Cells(6, 2).Value
paster = "formula"
'This starts at row 6 and loops until it hits the last row
For i = 6 To lastrow
Worksheets("y").Cells(i, (myvalue) + 21).Cells = paster
Next
'I dont really know what ".FormulaR1C1" is supposed to accomplish so I didn't include it.
End Sub
随意提出进一步的问题。
HTH