运行时错误'1004' - 对象'_Global'的方法'范围'失败 [英] Run-time error '1004' - Method 'Range' of object'_Global' failed

查看:179
本文介绍了运行时错误'1004' - 对象'_Global'的方法'范围'失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VBA中有一个问题,一行抛出一个错误。



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



代码如下:

 '查找客户输入列
对于范围内的每个单元格(B4:M4 )

如果cell.Value = strLeftMonth然后
DataImportColumn = cell.Column

如果

下一个


对于每个单元格工作表(数据客户月度2013​​)。范围(A3:A9999)

'第一个客户
如果cell.Value = strFirstCustomer然后
DataImportRow = cell.Row

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

运行上述代码后;代码崩溃,在 asterisk'd 行上提供 1004运行时错误。另外 DataImportColumn 的值为 7 DataImportRow 具有价值 5



现在我担心的是,列不被引用为数字而是字母,因此它必须是我的代码无法工作,因为它是一个可怕的参考。有没有人有任何建议,我可以如何做上述工作?/ p>

解决方案

您的范围值不正确。您正在引用不存在的单元格75。您可能希望使用R1C1符号方便地使用数字列,而无需转换为字母。



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

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

这应该解决你的问题。


I have a problem in VBA with a line throwing back an error.

What the macro is intended to do is find a particular cell then paste data into it.

The code is as following:

'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

After running the above code; The code crashes giving the 1004 run-time error on the asterisk'd line. Also DataImportColumn has a value of 7 and DataImportRow has a value of 5.

Now my concern is that Columns aren't referenced as numbers but letters, so it must be that my code can never work because its a terrible reference.

Does anyone have any suggestions how I can make the above work?

解决方案

Your range value is incorrect. You are referencing cell "75" which does not exist. You might want to use the R1C1 notation to use numeric columns easily without needing to convert to letters.

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

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

This should fix your problem.

这篇关于运行时错误'1004' - 对象'_Global'的方法'范围'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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