为什么我会收到运行时错误“1004”在 MacBook 上,当我从 PC 版本的 VBA 复制代码时

发布于 2025-01-17 02:17:11 字数 505 浏览 0 评论 0原文

我是 VBA 和学习新手;但是,我也在我的 MAC 而不是 PC 上运行 VBA。话虽如此,我将代码复制下来,就像我在 PC 使用的 VBA 中看到的那样,我收到运行时错误“1004”对象“_Global”的方法“范围”失败。有人可以向我解释一下这是为什么吗?

我的代码很简单: MonthArray(1) = Range("myMonths").Cells(i,1).value

大家有什么想法吗?

Sub Array_OneDimension()
Dim MonthArray(1 To 12) As String
Dim i As Byte

    For i = 1 To 12
        MonthArray(i) = Range("myMonths").Cells(i, 1).Value 'This is where the error is
        
    
    Next i

End Sub

我期望代码循环遍历范围并提取本地窗口中的值。

I am new to VBA and learning; however, I am also running VBA on my MAC instead of PC. That being said, I copy the code down just like I have seen in VBA used by PCs and I get a run-time Error '1004'Method 'Range' of object '_Global' failed. Can someone please explain to me why that is?

My code is simple: MonthArray(1) = Range("myMonths").Cells(i,1).value

Thoughts anyone?

Sub Array_OneDimension()
Dim MonthArray(1 To 12) As String
Dim i As Byte

    For i = 1 To 12
        MonthArray(i) = Range("myMonths").Cells(i, 1).Value 'This is where the error is
        
    
    Next i

End Sub

I was expecting the code to loop through the range and pull out the value in the locals window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文