HELP: VBA Run-time error '-2147417848 (80010108)'

xunda_gunda

New Member
Joined
Aug 17, 2012
Messages
22
Hello,

I am trying to run simple macro but I get this error:

VBA Run-time error '-2147417848 (80010108)':
Method 'Range' of object '_Worksheet' failed


My procedure is following:

Rich (BB code):
Sub Fill_Empty_Cells_with_Formulas()
    Application.ScreenUpdating = False
    Dim rng As Range
    Dim i As Long
    Set rng = Workbooks("Book1").Worksheets(1).Range("D15:D139")
        For Each cell In rng
            If cell.Value = "" Then
                cell.Offset(0, 0).Value = "=IF(ISTEXT(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE)),"""",IF(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE)<12,"""",IF(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE)<=$D$8,"""",IF(OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE),-12,2)<>"""",MIN(OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE),-12,2),INDIRECT(ADDRESS(ROW()-1,COLUMN()+3,4),TRUE)),""""))))"
            End If
        Next
    Application.OnTime Now + TimeValue("00:00:05"), "Fill_Empty_Cells_with_Formulas"
    Application.ScreenUpdating = True
End Sub

I just want that this code run in range mentioned above - "D15:D139".

What am I doing wrong?

Please help :(
 
Last edited by a moderator:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Perhaps:-
Rich (BB code):
    Set rng = Workbooks("Book1.xlsm").Worksheets(1).Range("D15:D139")
 
Last edited by a moderator:
Upvote 0
Is there a chance that your workbook/worksheet is protected? If not maybe you have error or invalid values in that range
 
Upvote 0
Perhaps:-
Code:
    Set rng = Workbooks("Book1[COLOR=#FF0000].xlsm[/COLOR]").Worksheets(1).Range("D15:D139")

I corrected but same error.

Code:
Sub Fill_Empty_Cells_with_Formulas()    Application.ScreenUpdating = False
    Dim rng As Range
    Dim i As Long
    Set rng = Workbooks("Book1.xlsm").Worksheets(1).Range("D15:D139")
        For Each cell In rng
            If cell.Value = "" Then
                cell.Offset(0, 0).Value = "=IF(ISTEXT(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE)),"""",IF(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE)<12,"""",IF(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE)<=$D$8,"""",IF(OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE),-12,2)<>"""",MIN(OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN()-2,4),TRUE),-12,2),INDIRECT(ADDRESS(ROW()-1,COLUMN()+3,4),TRUE)),""""))))"
            End If
        Next
    Application.OnTime Now + TimeValue("00:00:05"), "Fill_Empty_Cells_with_Formulas"
    Application.ScreenUpdating = True
End Sub

Is there a chance that your workbook/worksheet is protected? If not maybe you have error or invalid values in that range

No workbook is not protected. In that range I have Formulas or Numbers. This code should find blank cells (if there are any) and insert formula.
 
Upvote 0
try changing
Code:
for each cell in rng

to

Code:
for each cell in rng.cells

Thanks for trying but same error :(

Code:
[COLOR=#333333]Set rng = Workbooks("Book1.xlsm").Worksheets(1).Range("D15:D139")[/COLOR]

This part have problem :(
But can't understand what exactly :(
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top