VBA Excel使序列号数组 [英] VBA Excel make array of sequential numbers

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

问题描述

目前我正在VBA for Excel中工作,但实际上只精通Matlab.对于我的工作,重要的是要留在vba的内存中(而不是在Excel的工作表中)以节省时间.我需要做的是制作一个连续整数数组,比如 4000 到 5000.在matlab中,这真的很容易,我只要... i = 4000:5000或i = 4000:1:5000.第二种情况下的1是我的步骤".我想知道在vba中达到此结果的最佳方法是什么?谢谢

I am working in VBA for Excel at the moment but am really only versed in Matlab. It's important for my work to stay in the memory of vba (not on the worksheets of excel) for time purposes. What I need to do is make an array of sequential integers, say 4000 through 5000. In matlab this is really easy, I would just do... i = 4000:5000, or i=4000:1:5000. With the 1 in the second case being my 'step.' I was wondering what is the best way to achieve this result in vba? Thanks

推荐答案

不循环-发布后在上方看到罗里(Rory)的相同答案

Without looping - Just seen Rory's same answer above after posting

Sub MakeArray()
    Dim x As Long, y As Long, arr As Variant
    x = 4000: y = 5000
    arr = Evaluate("Row(" & x & ":" & y & ")")

    'Show result
    Sheets(1).Range("A1").Resize(y - x + 1) = arr
End Sub

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

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