2010-01-18 7 views
0

J'essaie d'obtenir une macro convertir de VBA sur vb.net et je reçois une erreur de type incompatibles et ne peut pas comprendre. J'espère que quelqu'un ici pourra m'aider.VB.net Excel tri

Ceci est le 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 

C'est le code de la 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 

Toute aide serait appréciée.

Merci!

+2

Sur quelle ligne, vous obtenez l'erreur – shahkalpesh

+0

I Je reçois une erreur d'incompatibilité de type sur oRange.Sort (Order1: = Excel.XlSortOrder.xlAscending, _ Key1: = oRange ("J2"), _ En-tête: = Excel.XlYesNoGuess.xlOui, MatchCase: = False, _ Orientation: = Excel.XlSortOrientation.xlSortColumns, _ DataOption1: = Excel.XlSortDataOption.xlSortNormal, _ DataOption2: = Excel.XlSortDataOption.xlSortNormal, _ DataOption3: = Excel.XlSortDataOption.xlSo rtNormal) – Lora

Répondre

1

changement simple de la première ligne comme ceci: oRange.Sort (Order1: = Excel.XlSortOrder.xlAscending, Touche1: = oRange ("J2") _

+0

Merci, j'ai enfin réussi à le faire fonctionner. Voici mon résultat: oRange.Sort (key1: = Orangé (2, 9), ORDER1: = Excel.XlSortOrder.xlAscending, _ tête: = Excel.XlYesNoGuess.xlYes, matchCase: = False, _ Orientation: = Excel.XlSortOrientation.xlSortColumns, _ DataOption1: = Excel.XlSortDataOption.xlSortNormal, _ DataOption2: = Excel.XlSortDataOption.xlSortNormal, _ DataOption3: = Excel.XlSortDataOption.xlSortNormal) – Lora

Questions connexes