Worksheetfunction Large doesn't work always

ER_Neha

Board Regular
Joined
Jul 25, 2020
Messages
130
Office Version
  1. 365
Platform
  1. Windows
Hello friends,

I have a query that, suppose I have two sheets named - SHEET1 & SHEET2

I write a code for sheet1 that contains the raw data , which includes worksheetfunction like LARGE

But i want the large numbers obtained from sheet1 to be extracted to sheet2

While I run the code , if i have opened my sheet2 , and run the code it shows me a run time error 1004 stating that unable to get the large property of the worksheet function class.

but the same code runs well while i have my sheet1 opened , it provides me the large numbers in the sheet2, with no error at all.

Kindly provide me with the detail, why it happens, I will be glad to learn.
 

Some videos you may like

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.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,624
Office Version
  1. 365
Platform
  1. Windows
Difficult to say for certain, without seeing the code, but I suspect you haven't qualified the range with the sheet name.
 

ER_Neha

Board Regular
Joined
Jul 25, 2020
Messages
130
Office Version
  1. 365
Platform
  1. Windows
Hello Fluff, Please I am attaching the code, your explanation will be a great help. Also I am attaching the screenshot of the error, which i am getting if i run the code while i have opened the sheet2

VBA Code:
Sub Macro()
Dim i As Double
Dim j As Double

Dim od As Worksheet
Dim nw As Worksheet

Set od = Sheets("Sheet1")
Set nw = Sheets("Sheet2")

For i = 1 To 5
    j = od.Application.WorksheetFunction.Match(od.Application.WorksheetFunction.Large(Range("b2:b20"), i), Range("b2:b20"), 0)
    nw.Range("a" & i & ":" & "b" & i).Value = od.Range("a" & j + 1 & ":" & "b" & j + 1).Value
Next i

End Sub
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    146.7 KB · Views: 2

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,624
Office Version
  1. 365
Platform
  1. Windows
You haven't qualified the ranges, it should be
VBA Code:
    j = Application.WorksheetFunction.Match(Application.WorksheetFunction.Large(od.Range("b2:b20"), i), od.Range("b2:b20"), 0)
 
Solution

ER_Neha

Board Regular
Joined
Jul 25, 2020
Messages
130
Office Version
  1. 365
Platform
  1. Windows
Thank u so much. It worked
You haven't qualified the ranges, it should be
VBA Code:
    j = Application.WorksheetFunction.Match(Application.WorksheetFunction.Large(od.Range("b2:b20"), i), od.Range("b2:b20"), 0)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,624
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,725
Messages
5,626,512
Members
416,187
Latest member
L_D18

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
Top