vba ERROR 1004 method range of object_worksheet failed

anand3dinesh

Board Regular
Joined
Dec 19, 2019
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have below code to assign range of cells value into Arr variable.
where Arr is variant, not sure what causing "vba ERROR 1004 method range of object_worksheet failed".
could you please help me to fix this?

Thanks in advance, Please see below code. error is in red line below


Dim wKPI As Workbook
Dim wKPIsh As Worksheet
Dim Arr as Variant

For Each wKPIsh In wKPI.Worksheets
cKPI_Lcol = cKPIsh.Range("XFD7").End(xlToLeft).Column
If cKPIsh.Name = wKPIsh.Name Then
'Declare Last row variables
wKPI_Lrow = wKPIsh.Range("B1048576").End(xlUp).Row
wKPI_Lcol = wKPIsh.Range("XFD7").End(xlToLeft).Column

For wKPIr = 8 To wKPI_Lcol
Arr = wKPIsh.Range(Cells(wKPIr, 2), Cells(wKPIr, wKPI_Lcol)).Value
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
It needs to be like
VBA Code:
Arr = wKPIsh.Range(wKPIsh.Cells(wKPIr, 2), wKPIsh.Cells(wKPIr, wKPI_Lcol)).Value
 
Upvote 0
Solution
Once you fix that, you might also want to look at your For Loop, it seems to be cycling through rows but it using the Last Column where you would expect the Last Row No.

Rich (BB code):
For wKPIr = 8 To wKPI_Lcol
'Shouldn't this be
For wKPIr = 8 To wKPI_Lrow
 
Upvote 0
Glad we could help & thanks for the feedback.
As Alex has said, it looks as though your loop is wrong.
 
Upvote 0
Once you fix that, you might also want to look at your For Loop, it seems to be cycling through rows but it using the Last Column where you would expect the Last Row No.

Rich (BB code):
For wKPIr = 8 To wKPI_Lcol
'Shouldn't this be
For wKPIr = 8 To wKPI_Lrow
oh yeah, you are right. Thanks mate
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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