VB.net Excel sorting

Posted by Lora on Stack Overflow See other posts from Stack Overflow or by Lora
Published on 2010-01-18T17:02:47Z Indexed on 2010/03/18 16:01 UTC
Read the original article Hit count: 293

Filed under:
|

I am trying to get a macro convert from VBA over to vb.net and I am getting a type mismatched error and can't figure it out. I am hoping someone here will be able to help me.

This is the code.

Sub SortRawData()
    Dim oSheet As Excel.Worksheet
    Dim oRange As Excel.Range


    Try
        oSheet = SetActiveSheet(mLocalDocument, "Sheet 1")
        oRange = mApplication.ActiveSheet.UsedRange


        oRange.Sort(Key1:=oRange("J2"), Order1:=Excel.XlSortOrder.xlAscending, _
            Header:=Excel.XlYesNoGuess.xlYes, OrderCustom:=1, MatchCase:=False, _
            Orientation:=Excel.XlSortOrientation.xlSortColumns, _
            DataOption1:=Excel.XlSortDataOption.xlSortNormal, _
            DataOption2:=Excel.XlSortDataOption.xlSortNormal, _
            DataOption3:=Excel.XlSortDataOption.xlSortNormal)


             Catch ex As Exception
        ErrorHandler.HandleError(ex.Message, ex.Source, ex.StackTrace)

    End Try


End Sub

This is the code from the macro

Sub SortRawData(ByRef poRange As Range)

Set poRange = Application.ActiveSheet.UsedRange


poRange.Sort Key1:=Range("J2"), Order1:=xlAscending _
, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal


poRange.Sort Key1:=Range("D2"), Order1:=xlAscending, _
                   Key2:=Range("H2"), Order2:=xlAscending, _
                   Key3:=Range("L2"), Order3:=xlAscending, _
                   Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:= _
                   xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
    DataOption3:=xlSortNormal


End Sub

Any help would be appreciated.

Thanks!

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about excel-vba