I have a function HVL_Sort that sorts the values in InputRange according to the values in SortByRange. This function is used as an array worksheetfunction at several places in my workbook.
Inspired by CautionMP in an earlier post to this thread I use the following that gives the range from which my VBA function is called:
Application.Caller.Address(False, False, xlA1, True)
The function header :
Function HVL_Sort(ByVal InputRange As Range, _
ByVal SortByRange As Range, _
Optional ByVal Sort_Ascending As Boolean = True) As Variant
The statements :
Debug.Print InputRange.Address(False, False, xlA1, True)
Debug.Print SortByRange.Address(False, False, xlA1, True)
Debug.Print Application.Caller.Address(False, False, xlA1, True)
give the results :
'[My Book.xls]aSheet'!C11:Q11
'[My Book.xls]aSheet'!C12:Q12
'[My Book.xls]aSheet'!C13:Q13
That is : Sort the values in aSheet!C11:Q11 according to aSheet!C12:Q12 and place the result in aSheet!C13:Q13.
Error trapping :
1. InputRange and SortByRange must have the same dimensions.
2. These ranges should not be 2-dimensional, i.e. only (part of) a row or a column.
3. The generic routine called to do the actual sorting might return an error code.
If an error is recognized some information including the above 3 ranges are presented in a message box.
________________________
Helge Larsen