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

s0u*_*2up 5 excel vba excel-2007

我在 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
Run Code Online (Sandbox Code Playgroud)

运行以上代码后;代码崩溃,导致1004 run-time errorasterisk'd线。还DataImportColumn具有 的 值7DataImportRow的 值5

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

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

App*_*Pie 9

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

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

Range("R" & DataImportRow & "C" & DataImportColumn).Offset(0, 2).Value = iFirstCustomerSales
Run Code Online (Sandbox Code Playgroud)

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