Click here to Skip to main content
16,012,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two columns of data that I wish to sort. The code I have used gives me an error of;

C#
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Exception from HRESULT: 0x800A03EC


The code worked okay when I was using early binding!

Data looks like this in columns A and B before sorting
C#
1	Alan Wicks
9	Alan Wicks
10	Alan Wicks
1	Bernard McTernan
9	Bernard McTernan
1	Bob Horne
2	Bob Horne
3	Bob Horne


What I have tried:

VB
'List of Imports
Imports System
Imports System.IO
Imports System.Xml
Imports System.Data.OleDb

'List of Public Const
    Public Const dbAscending = 1
    Public Const dbSortNormal = 0
    Public Const dbSortColumns = 3
    Public Const dbYes = 1

'bit of code causing the failure
            oSheet.Range(oSheet.Cells(a, 1), oSheet.Cells(b, 2)).Sort(
            Key1:=oSheet.Columns(1), Order1:=dbAscending,
            Key2:=oSheet.Columns(2), Order2:=dbAscending,
            Header:=dbYes,
            OrderCustom:=1, MatchCase:=False,
            Orientation:=dbSortColumns,
            DataOption1:=dbSortNormal,
            DataOption2:=dbSortNormal)
Posted
Updated 23-Feb-16 8:06am

1 solution

Decided that the way forward is to put the data into a datatable and sort there; then transfer sorted data to excel sheet.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900