Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Excel Fields from .net

Status
Not open for further replies.

angel106

Technical User
Aug 1, 2005
39
0
0
US
I need to find a way to sort based on ascending numbers: I recorded a macro in excel however i can;t seem to put it into .net code. The code below is from the recorded macro

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 08/29/2005 by colindolcetti
'

'
Range("A1:K194").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub



This code below here is the .net code that i would like to put my excel code into:


For intLoop = 0 To Me.nextStepArrList.Count - 1
xlsheet.Cells(intRowLoc, intCurrentCol) = CType(opcodesarrlist(intLoop), OpCodes).opcode

Dim xlRange As Excel.Range
xlRange = xlsheet.Cells(intRowLoc, intCurrentCol)
xlRange.Select()
With CType(xlApp, Excel.Application).Selection.interior
If CType(opcodesarrlist(intLoop), OpCodes).opcode Then
.xlascending()
End If
End With
intRowLoc += 1
Next


If i use this code it error out what i'm a missing?
 
You have to reference the Excel library and create instances of an application, workbook and worksheet objects.
 
Below is the new code:

When i run this code i get an error message sort method range class failed......

What i want to do is to be able to sort the first col down.



intRowLoc = 2
For intLoop = 0 To Me.nextStepArrList.Count - 1
Dim xlRange As Excel.Range
Dim xlascending As Excel._Worksheet
xlsheet.Cells(intRowLoc, intCurrentCol) = CType(opcodesarrlist(intLoop), OpCodes).opcode
With CType(xlApp, Excel.Application)
xlsheet.Cells(intRowLoc, intCurrentCol).sort(Order1:=xlascending)
End With

intRowLoc += 1

Next
intCurrentCol += 1
 
I don't see where you've set your Worksheet equal to any instance?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top