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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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