gpt4 book ai didi

excel - 运行时错误 '1004' - 对象“_Global”的方法 'Range' 失败

转载 作者:行者123 更新时间:2023-12-01 00:17:05 35 4
gpt4 key购买 nike

我在 VBA 中遇到了一个问题,其中一行抛出了错误。

宏的目的是找到一个特定的单元格,然后将数据粘贴到其中。

代码如下:

'To find Column of Customer imput
For Each cell In Range("B4:M4")

If cell.Value = strLeftMonth Then
DataImportColumn = cell.Column

End If

Next


For Each cell In Worksheets("data customer monthly 2013").Range("A3:A9999")

'First Customer
If cell.Value = strFirstCustomer Then
DataImportRow = cell.Row

Range(DataImportColumn & DataImportRow).Offset(0, 2).Value = iFirstCustomerSales ****
End If

运行上述代码后;代码崩溃给出 1004 run-time errorasterisk'd线。还有 DataImportColumn值为 7DataImportRow值为 5 .

现在我担心的是列不是以数字而是字母来引用的,所以一定是我的代码永远无法工作,因为它是一个糟糕的引用。

有人对我如何使上述工作有任何建议吗?

最佳答案

您的范围值不正确。您正在引用不存在的单元格“75”。您可能希望使用 R1C1 表示法轻松使用数字列,而无需转换为字母。

http://www.bettersolutions.com/excel/EED883/YI416010881.htm

Range("R" & DataImportRow & "C" & DataImportColumn).Offset(0, 2).Value = iFirstCustomerSales

这应该可以解决您的问题。

关于excel - 运行时错误 '1004' - 对象“_Global”的方法 'Range' 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20601110/

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