cancel
Showing results for 
Search instead for 
Did you mean: 

VBA Excel Sorting

Anonymous
Not applicable
Hi Guys, I created a below code, and could not find what is wrong there - check code does not show anything. Exception details after calculation stage attached. Code: dim wb as excel.workbook dim ws as excel.worksheet 'Dim wb as Object = GetWorkbook(handle,workbookname) 'Dim ws as Excel.Worksheet Dim Xlapp as Object=getobject(,"Excel.Application") for each wb in Xlapp.workbooks if wb.name = [workbookname] then wb.activate exit for end if next ws = wb.worksheets(worksheetname) ws.activate ws.Range("A3:K"&[Number_of_Rows]-1).Sort.SortFields.Clear ws.Range("A3:K"&[Number_of_Rows]-1).Sort.SortFields.Add (Key:= ws.range("E3:E"&[Number_of_Rows]), SortOn:=1, Order:=2, DataOption:=1) With ws.Range("A3:K"&[Number_of_Rows]-1) .Sort .SetRange (ws.Range("A3:K"&[Number_of_Rows]-1)) .Header = 0 .MatchCase = False .Orientation = 1 .SortMethod = 1 .Apply End With handle, Number_of_Rows, workbookname, and worksheetname are Inputs for the code above. Many Thanks, Jarek
0 REPLIES 0