Cell Referencing Error - Method 'Range' of object'_Worksheet' failed

alexb523

Board Regular
Joined
Dec 12, 2013
Messages
115
I have seen examples of this issue out there, but i am having problems solving it when it comes to solving my own.

Please take a look at my code below, it is bugging in the array formula.

Code:
    Dim TableNames As Worksheet
    Dim ss As Worksheet
    Dim ssclaim As Worksheet
    Dim sspercent As Worksheet
    Dim lrTableNames As Long
    
    Set TableNames = b1.Sheets("TableNames")
    Set ss = b1.Sheets("SS1617_TP164")
    Set ssclaim = b1.Sheets("SSbyClaim1617_TP177")
    Set ssprecent = b1.Sheets("SSpercentile1617_TP198")
    lrTableNames = TableNames.Range("B" & Rows.Count).End(xlUp).Row
    Dim Lastrow As Long
    Lastrow = ss.Range("B" & Rows.Count).End(xlUp).Row


    For Each iRow In ss.Range("L2:L" & Lastrow)
        ss.Range("L" & iRow).FormulaArray = _
        "=INDEX(TableNames!$J$2:$J" & lrTableNames & ",MATCH(1,(TableNames!$D$2:$D" & lrTableNames & "=$C" & iRow & ")*(TableNames!$E$2:$E" & lrTableNames & "=$B" & iRow & ")*(TableNames!$A$2:$A" & lrTableNames & "=""Average Overall Scale Score""),0))"
    Next iRow
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
For Each iRow In ss.Range("L2:L" & Lastrow)

Dim irow as long

For irow =2 to to lastrow


ss.Range("L" & iRow).FormulaArray = _
"=INDEX(TableNames!$J$2:$J" & lrTableNames & ",MATCH(1,(TableNames!$D$2:$D" & lrTableNames & "=$C" & iRow & ")*(TableNames!$E$2:$E" & lrTableNames & "=$B" & iRow & ")*(TableNames!$A$2:$A" & lrTableNames & "=""Average Overall Scale Score""),0))"
Next iRow
 
Last edited:
Upvote 0
Or, without looping:

Code:
With ss.Range("L2:L" & Lastrow)
    .Formula = "=INDEX(TableNames!$J$2:$J$" & lrTableNames & ",MATCH(1,(TableNames!$D$2:$D$" & lrTableNames & "=$C2)*(TableNames!$E$2:$E$" & lrTableNames & "=$B2)*(TableNames!$A$2:$A$" & lrTableNames & "=""Average Overall Scale Score""),0))"
    .FormulaArray = .FormulaR1C1
End With

By the way, you have a typo here, which will cause problems if you use sspercent later in your code:

Code:
Dim sspercent As Worksheet

Set ssp[COLOR=#ff0000][B]re[/B][/COLOR]cent = b1.Sheets("SSpercentile1617_TP198")

A good reason to always use Option Explicit!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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