VBA简单的macros来复制公式

我想从列中复制公式到行中。 公式在地址中没有$签名,所以我不能使用特殊的粘贴选项,因为它会改变每个单元格公式中的地址。

我试图运行macros,但它只复制列中的最后一个单元格到行中的所有人。

Sub Zamiana() For Each y In Range("A1:B1") For Each X In Range("A2:A3") y.Formula = X.Formula Next Next End Sub 

在此先感谢帮助:)

一个简单的方法是通过一个变体数组和transpose函数来传递公式。

喜欢这个:

 Sub TransposeFormulas() Dim rSrc As Range Dim rDst As Range Dim vSrc As Variant Set rSrc = Range("A1:B1") Set rDst = Range("A2") ' top left cell of destination vSrc = rSrc.Formula ' copy source formulas into a variant array ' size the destination range and transpose formulas into it rDst.Resize(UBound(vSrc, 2), UBound(vSrc, 1)).Formula = _ Application.Transpose(vSrc) End Sub 

尝试添加两个索引,一个用于列,一个用于行,并放置一个for循环,就像这样

 Sub Zamiana() iR = 1 iC = 0 For Each y In Range("A1:B1") r = y.Row + iR c = y.Column - iC Cells(r, c).Formula = y.Formula iR = iR + 1 iC = iC + 1 Next End Sub