VBA:反转数组? [英] VBA: Reverse an array?

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

问题描述

如何反转由整数组成的数组,例如:

How could I reverse an array that is full of integers e.g.:

[1;5;8;45;54]

收件人:

[54;45;8;5;1]

是否已建好在我可以使用的函数中?

Are there any built in functions I could use?

我尝试使用方法:

Array.Reverse(arr)

我从工具>引用中添加了Mscorlib.dll,但显示错误:语法错误。在Array.Reverse(arr)位置。

I added Mscorlib.dll from Tools > References, but it showed error: Syntax error. At the Array.Reverse(arr) location.

推荐答案

Array.Reverse

Array.Reverse sounds like VB.Net, not VBA.

Chip Pearson的功能几乎可以与数组(和其他结构)一起使用。

Chip Pearson has functions for just about anything you will want to do with arrays (and other structures).

http://www.cpearson.com/excel /vbaarrays.htm -> ReverseArrayInPlace

相关部分是:

Ndx2 = UBound(InputArray)
' loop from the LBound of InputArray to the midpoint of InputArray
For Ndx = LBound(InputArray) To ((UBound(InputArray) - LBound(InputArray) + 1) \ 2)
    'swap the elements
    Temp = InputArray(Ndx)
    InputArray(Ndx) = InputArray(Ndx2)
    InputArray(Ndx2) = Temp
    ' decrement the upper index
    Ndx2 = Ndx2 - 1
Next Ndx

这篇关于VBA:反转数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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