Argument for Excel.Range.Sort

partham

Active member
Joined
Dec 27, 2005
Messages
41
Location
Kolkata, India
Programming Experience
10+
Dear Sir,
I am required to sort worksheets of data in a workbook using the same column as key. My application is in VB.Net and I am using Excel Interop. I found this function Excel.Range.Sort to wort the data. However, I do not know what I need to pass as an argunemt for Type. No matter what I try, I get the error, "Type mismatch".

l_strRange = GetWorksheetColumnName(1) + "1:" + GetWorksheetColumnName(l_dtblData.Columns.Count - 1) + CType(l_srlWorkSheetRowCounter.GetByIndex(l_sCtr), Integer).ToString
l_objDataRange = l_objWorksheet.Range(l_strRange)
l_objDataRange.Select()
l_objDataRange.Sort(l_objKeyRange(0), Excel.XlSortOrder.xlAscending, l_objKeyRange(1), GetType(Object), Excel.XlSortOrder.xlAscending, l_objKeyRange(2), Excel.XlSortOrder.xlAscending, Excel.XlYesNoGuess.xlYes, 1, True, Excel.XlSortOrientation.xlSortColumns)


Please advise.
Rehards,
 
Dear Sir,

I was able to work around the problem using the following code. I am putting it here in case it is useful to someone.

VB.NET:
l_objDataRange.Sort( _
Key1:=l_objKeyRange(0), _
Key2:=l_objKeyRange(2), _
Key3:=l_objKeyRange(3), _
Order1:=Excel.XlSortOrder.xlAscending, _
Order2:=Excel.XlSortOrder.xlAscending, _
Order3:=Excel.XlSortOrder.xlAscending, _
Header:=Excel.XlYesNoGuess.xlYes, _
OrderCustom:=1, _
MatchCase:=True, _
Orientation:=Excel.XlSortOrientation.xlSortColumns, _
DataOption1:=Excel.XlSortDataOption.xlSortNormal, _
DataOption2:=Excel.XlSortDataOption.xlSortNormal, _
DataOption3:=Excel.XlSortDataOption.xlSortNormal _
)


Regards,
 
Back
Top