29-09-21 03:38 PM
Hi,
I want to sort column from excel file by predefined order. how can we achieve it?
30-09-21 11:58 AM
30-09-21 01:52 PM
03-10-21 12:26 PM
Dim worksheet,Excel As Object
Dim rRng as Object
Dim Header1 as integer
try
Excel = GetWorkbook(handle,Nothing)
worksheet = GetWorkbook(handle,Nothing).ActiveSheet
rRng = worksheet.Range(Data_StartCell,Data_EndCell)
if HeaderPresent = true then
Header1=1
else if HeaderPresent = false then
Header1=2
end if
rRng.Sort(Key1:=worksheet.Range(Order_StartCell,Order_EndCell), Order1:=OrderType,Header:=Header1)
Success = true
catch e as Exception
Success = false
End try
Input Variables Used- handle , Data_StartCell , Data_EndCell, Order_StartCell, Order_EndCell, OrderType, HeaderPresent
Output Variables - Success
Suppose you want have data from A1:E20 column and you need to sort column B only. So below are the inputs which you can use:
Data_StartCell- "A1"
Data_EndCell - "E20"
Order_StartCell- "B1"
Order_EndCell- "B20"
OrderType- 1 (it is of Number type and 1 for Ascending and 2 for Descending)
HeaderPresent- True or False depending you have headers or not
Hope the solution works for you.
03-10-21 12:26 PM