Monday, 19 August 2013

Excel Sorting(Ascending , Descending) By Rows and Columns

Excel Sorting By Row:
Const xlAscending = 1
Const xlNo = 2
Const xlSortRows = 2
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open(“C:Documents and Settingsmohan.kakarlaDesktopDocs1.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
Excel Sorting By Colum :
Const xlAscending = 1′represents the sorting type 1 for Ascending 2 for Desc
Const xlYes = 1
Set objExcel = CreateObject(“Excel.Application”)’Create the excel object
objExcel.Visible = True’Make excel visible
Set objWorkbook = _
objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\Docs1.xls”)’Open the
document
Set objWorksheet = objWorkbook.Worksheets(1)’select the sheet based on the index .. 1,2 ,3 …
Set objRange = objWorksheet.UsedRange’which select the range of the cells has some data other than blank
Set objRange2 = objExcel.Range(“A1″)’ select the column to sort
objRange.Sort objRange2, xlAscending, , , , , , xlYes
set objExcel=nothing

No comments:

Post a Comment