Method range of object failed - Please help

Status
Not open for further replies.

whitethorn

New Member
Joined
Jun 20, 2018
Messages
3
Hi All,


I am trying to define a variant based on the results of another loop and I am currently using the below syntax, however i am getting a method range of object failed. I've been trying for about 3 hours to figure this out and have made some changes but can't seem to see what's going wrong. Any ideas?


Code:
For j = 1 To finalrow3
    
    For l = 1 To 200
        If base(j, 1) = firstlast(l, 2) And Year(dates(j, 1)) <= firstlast(l, 1) And Year(dates(j, 2)) >= firstlast(l, 1) Then
            first = firstlast(l, 3)
            last = firstlast(l, 4)
         End If
         
         If first = 0 Then Exit For
            Dim base1(), bil(), mh() As Variant
            
             base1() = Capacity.Range(Cells(first, 8), Cells(last, 8)) ' get method range object failed here 
             bil() = Capacity.Range(Cells(first, 9), Cells(last, 15))
             mh() = Capacity.Range(Cells(first, 23), Cells(last, 24))
        Next l
    Next j

Thank you
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this.
Code:
Dim base1(), bil(), mh() As Variant

    For j = 1 To finalrow3

        For l = 1 To 200
            If Base(j, 1) = firstlast(l, 2) And Year(dates(j, 1)) <= firstlast(l, 1) And Year(dates(j, 2)) >= firstlast(l, 1) Then
                first = firstlast(l, 3)
                last = firstlast(l, 4)
            End If

            If first = 0 Then Exit For
            With Capacity
                base1() = .Range(.Cells(first, 8), .Cells(last, 8)) ' get method range object failed here
                bil() = .Range(.Cells(first, 9), .Cells(last, 15))
                mh() = .Range(.Cells(first, 23), .Cells(last, 24))
            End With
        Next l
    Next j
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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