gpt4 book ai didi

excel - 为什么我不能在 Excel 2016 VBA 中 ReDim 索引为 LongPtr 或 LongLong 的数组

转载 作者:行者123 更新时间:2023-12-02 21:20:16 26 4
gpt4 key购买 nike

我习惯在 Excel 2010(Windows 7 64 位)上使用以下代码,效果很好。

Sub code_on_2010()
Dim i As Long

i = InputBox("input integer number")
ReDim a(i) As Variant
'....
End Sub

最近,我将电脑升级到 Windows 10(64 位)和 Excel 2016(64 位)。由于我知道 64 位长整数类型的新类型名称,我重写代码如下:

Sub code_on_2016_with_LongPtr()
Dim i As LongPtr

i = InputBox("input integer number")
ReDim a(i) As Variant
'...
End Sub

它返回一个类型不匹配(错误 13) 错误。

即使我将 LongPtr 替换为 LongLong(如下所示),它也会返回 类型不匹配 错误。

Sub code_on_2016_with_LongLong()
Dim i As LongLong

i = InputBox("input integer number")
ReDim a(i) As Variant
'...
End Sub

有人能告诉我为什么我无法在 Excel 2016 VBA 中 ReDim 具有 LongPtr 或 LongLong 类型索引的数组吗?

最佳答案

Excel 64 位在代码中不需要 LongPtr 或 LongLong:

Option Explicit

Sub code_on_2010()
Dim i As Long 'declaring any other type won't speed up your code, and won't give a bigger range of possible numbers!
Dim h$
Dim a() 'basically says : a is a variable sized array of type variant
h = InputBox("input integer number") 'returns a string
if isnumeric(h) then i=clng(h)
ReDim a(i)
'....
End Sub

关于excel - 为什么我不能在 Excel 2016 VBA 中 ReDim 索引为 LongPtr 或 LongLong 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49085039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com