Hi,
Here's something from my "need to crunch these numbers so often might as well write a macro for it" libraries, slightly modified for your setup.
Doesn't do exactly what you asked, as it creates a new sheet instead. Figured this would work for you as well.
VB:
Public Sub GetOrderedList_CreateSheet()
Dim wksSource As Excel.Worksheet
Dim wksTarget As Excel.Worksheet
Dim rngSource As Excel.Range
Dim rngTarget As Excel.Range
Dim lMin As Long
Dim lMax As Long
Dim lRows As Long
Set wksSource = ActiveSheet
With wksSource.Columns(1)
Set rngSource = wksSource.Range(.Cells(1), .Cells(.Cells.Count).End(xlUp))
End With
lMin = Application.WorksheetFunction.Min(rngSource)
lMax = Application.WorksheetFunction.Max(rngSource)
lRows = lMax - lMin
If lRows = 0 Or lRows > wksSource.Rows.Count Then Exit Sub
Set rngSource = rngSource.Resize(rngSource.Rows.Count, 2)
Set wksTarget = ThisWorkbook.Worksheets.Add()
wksTarget.Name = "Ordered List"
Set rngTarget = wksTarget.Range(wksTarget.Cells(1, 1), wksTarget.Cells(lRows + 1, 2))
With rngTarget
.Cells(1, 1).Value = lMin
.Cells(1, 2).FormulaR1C1 = "=VLOOKUP(RC[-1]," & rngSource.Address(True, True, xlR1C1, True) & ",2,0)"
rngTarget.Columns(1).DataSeries _
Rowcol:=xlColumns, Type:=xlDataSeriesLinear, _
Step:=1, Trend:=False
.Columns(2).FillDown
On Error Resume Next
.SpecialCells(xlCellTypeFormulas, 16).Value = 0
On Error Goto 0
.Value = .Value
End With
End Sub
Bookmarks