Excel Sorting by Rows or/and Columns (Ascending or Descending)
Vote if this topic was useful to you
Excel Sorting by Rows or/and Columns (Ascending or Descending)
'Represents the sorting type 1 for Ascending, and 2 for Descending.
''Excel Sorting By Colum : You may parameterise the hard coded values
Function ExcelSortByColumns()
Const xlAscending = 1
Const xlYes = 1
'Create the excel object
Set objExcel = CreateObject(“Excel.Application”)
'Make excel visible
objExcel.Visible = True
'Open the document
Set objWorkbook = objExcel.Workbooks.Open(“C:\Users\sgajre\Desktop\ListOfTopics.xls”)
'select the sheet based on the index .. 1,2 ,3 …
Set objWorksheet = objWorkbook.Worksheets(1)
'Select the range of the cells which has some data other than blank
Set objRange = objWorksheet.UsedRange
'select the column to sort
Set objRange2 = objExcel.Range(“A1″)
objRange.Sort objRange2, xlAscending, , , , , , xlYes
set objExcel=nothing
End Function
'Represents the sorting type 1 for Ascending, and 2 for Descending.
''Excel Sorting By Row: You may parameterise the hard coded values
Function ExcelSortByRows()
Const xlAscending = 1
Const xlNo = 2
Const xlSortRows = 2
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open(“C:\Users\sgajre\Desktop\ListOfTopics.xls”)
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Cells(1,1).activate
Set objRange = objExcel.ActiveCell.EntireRow
objRange.Sort objRange, xlAscending, , , , , , xlNo, , , xlSortRows
set objExcel=nothing
End Function
''Excel Sorting By Colum : You may parameterise the hard coded values
Function ExcelSortByColumns()
Const xlAscending = 1
Const xlYes = 1
'Create the excel object
Set objExcel = CreateObject(“Excel.Application”)
'Make excel visible
objExcel.Visible = True
'Open the document
Set objWorkbook = objExcel.Workbooks.Open(“C:\Users\sgajre\Desktop\ListOfTopics.xls”)
'select the sheet based on the index .. 1,2 ,3 …
Set objWorksheet = objWorkbook.Worksheets(1)
'Select the range of the cells which has some data other than blank
Set objRange = objWorksheet.UsedRange
'select the column to sort
Set objRange2 = objExcel.Range(“A1″)
objRange.Sort objRange2, xlAscending, , , , , , xlYes
set objExcel=nothing
End Function
'Represents the sorting type 1 for Ascending, and 2 for Descending.
''Excel Sorting By Row: You may parameterise the hard coded values
Function ExcelSortByRows()
Const xlAscending = 1
Const xlNo = 2
Const xlSortRows = 2
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open(“C:\Users\sgajre\Desktop\ListOfTopics.xls”)
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Cells(1,1).activate
Set objRange = objExcel.ActiveCell.EntireRow
objRange.Sort objRange, xlAscending, , , , , , xlNo, , , xlSortRows
set objExcel=nothing
End Function
Similar topics
» How to delete rows range from the excel sheet
» How to add or delete columns to a QTP datatable sheet
» Working with Excel Objects using VBscript
» How to add or delete columns to a QTP datatable sheet
» Working with Excel Objects using VBscript
Permissions in this forum:
You cannot reply to topics in this forum
Thu Jun 19, 2014 11:31 am by thomasdfg
» How to identify the object when it is dynamically changing behavior
Wed Jun 18, 2014 6:37 pm by thomasdfg
» Patches for QTP 10, 11, 11.5
Wed Jun 18, 2014 6:04 pm by thomasdfg
» Retrieving data from Txt file into datatable
Wed Jun 18, 2014 5:32 pm by thomasdfg
» VB Script to count number of links in a web page.
Wed Jun 18, 2014 4:51 pm by thomasdfg
» Customized HTML reports in QTP
Wed Jun 18, 2014 4:42 pm by thomasdfg
» how to print values into a field of a web page, from a data table in qtp?
Wed Jun 18, 2014 4:37 pm by thomasdfg
» How to delete cookies using QTP?
Wed Jun 18, 2014 4:30 pm by thomasdfg
» When UFT Does Not Identify an Object
Wed Jun 18, 2014 4:23 pm by thomasdfg