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.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Difficult to say for certain, without seeing the code, but I suspect you haven't qualified the range with the sheet name.
 
Upvote 0
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: 8
Upvote 0
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)
 
Upvote 0
Solution
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)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,780
Messages
6,121,527
Members
449,037
Latest member
tmmotairi

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