Range sort causing index lookup value glitch

SRMPURCHASE

Board Regular
Joined
Dec 23, 2014
Messages
210
Office Version
  1. 2016
Platform
  1. Windows
In the following formula, whenever I sort the range with this formula (and others with similar problem), the lookup value will change by 3 - 7 rows after the sort is finished.

The range is sorted with the VBA following the Index formula. Is there a conflict between the two that causes the lookup value to not keep its relative position after the sort is finished?

=IFERROR(INDEX('PLANT ARO LIST'!$D$3:$D$41,MATCH('PO LOG'!J188,'PLANT ARO LIST'!$B$3:$B$41,"0")),"")

Sub POLOGSORT()
'
' POLOGSORT Macro
'

'
Range("B25:BJ300").Select
ActiveWorkbook.Worksheets("PO LOG").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("PO LOG").Sort.SortFields.Add Key:=Range( _
"B25:B300"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("PO LOG").Sort.SortFields.Add Key:=Range( _
"E25:E300"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("PO LOG").Sort
.SetRange Range("B25:BJ300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("BE25").Select
Application.CutCopyMode = False
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("F300").End(xlUp).Select
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Assuming the formula is on the "PO LOG" sheet, try removing the part in red
=IFERROR(INDEX('PLANT ARO LIST'!$D$3:$D$41,MATCH('PO LOG'!J188,'PLANT ARO LIST'!$B$3:$B$41,"0")),"")
 
Upvote 0
Such a simple solution, works as far as I can see. What caused the glitch with 'PO LOG'! in the formula?
 
Upvote 0
I've no idea, it's simply a problem I've come across in the past, so I never include the sheet name for the active sheet.
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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