在 VBA 中转置范围 [英] Transpose a range in VBA

查看:27
本文介绍了在 VBA 中转置范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 VBA 宏在 Excel 中转置一系列单元格,但出现了一些错误,主要是错误 91.

I am Trying to Transpose a range of cells in Excel through VBA macro but I am getting some errors, mostly Error 91.

我对 VBA 还很陌生,对函数也不太了解.

I am pretty new to VBA and don't have much idea about functions either.

Range(InRng).Select
Set Range1 = Selection
Dim DestRange As Range
Set DestRange = Application.WorksheetFunction.Transpose(Range1)

经过几个论坛后,这就是我想出的.需要注意的一件事是我不必将它们复制到任何其他单元格中.

After going through a couple of forums, this is what I have come up with. One thing to note is that I don't have to copy them into any other cells.

我想要实现的是创建一个协方差方法,在选项窗口中,用户可以选择范围,然后按列或行进行选择,这将影响产生的协方差矩阵.

What I am trying to achieve is to create a co-variance method and in the option window the user will have the option to select the range and then choose either by columns or rows, this will then affect the resulting covariance matrix.

推荐答案

这让你 X 和 X' 作为变体数组,你可以传递给另一个函数.

This gets you X and X' as variant arrays you can pass to another function.

Dim X() As Variant
Dim XT() As Variant
X = ActiveSheet.Range("InRng").Value2
XT = Application.Transpose(X)

要将转置的值作为范围,您必须通过工作表传递它,如这个答案.如果不了解协方差函数的工作原理,就很难看出您需要什么.

To have the transposed values as a range, you have to pass it via a worksheet as in this answer. Without seeing how your covariance function works it's hard to see what you need.

这篇关于在 VBA 中转置范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆