简体   繁体   中英

Run-time error '1004' Method 'Range' of object'_Global' failed

I have a macro that fills in some data at the DataCell location and a few other cells based on the information it finds on the master sheet. Once it finds a "blank" on the master sheet it stops. I then want it to select a range on my 'data' sheet and clear the contents of that range.

For some reason I get an error in trying to select the needed range. The code dies at:

Range("EmptyCell:AZ24").Select

I just need it to properly select the first part of the range. This first cell will vary depending on other portions of the macro.

I have looked through your other answers to similar problems and haven't been able to resolve the issue.

Set DataCell = cnsu2table.Offset(0, x + 1)
    If DataCell <> "" Then
    DataCell.Offset(-2, 0) = cnsu2por
    DataCell.Offset(-1, 0) = cnsu2fcr
    DataCell.Offset(1, 0) = Application.WorksheetFunction.HLookup(DataCell, cnsu2array, 51, False)
    ElseIf DataCell = "" Then
        Set EmptyCell = DataCell.Offset(-2, 0)
        Range("EmptyCell:AZ24").ClearContents

改用:

Range(EmptyCell, Range("AZ24")).ClearContents

Change:

Range("EmptyCell:AZ24").ClearContents

By:

Range(EmptyCell.Address & ":AZ24").ClearContents

You should also declare your EmptyCell variable as:

Dim EmptyCell as Range

before using it.


EmptyCell is a variable so putting it between quotation marks will not return the variable but will return the string "EmptyCell" not the object EmptyCell .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM