Okay, I am 50% toward having this figured out, but there are a couple of concepts that are new to me here and it is throwing me for a loop.

I am reading an Excel file into VB.NET. There are 4 columns containing dollar figures of varying amounts. Here is what I need to do is identify the columns with the highest $ figure, the next highest, etc. and mark them so that .NET can identify them (e.g. col3 is highest so rank1 variable is "col3" and so on).

So I am dealing with Excel Ojects which is new to me and sorting which is new to me. If it helps, here is how I am reading in the Excel file:

    xlsWorkBook = xlsApp.Workbooks.Open(folders(f).ToString & "\" & fileInFolder.ToString)
    xlsWorkSheet = xlsWorkBook.Worksheets("Sheet1")
    Dim ColumnNumber As Integer = xlsWorkSheet.Cells(1, StartColumn).Column

    For r = 6 To xlsWorkSheet.Range(StartColumn & "65536").End(xlUp).Row
    'Need sorting here

Recommended Answers

All 3 Replies

Do you want it sorted in the sheet or in your code?

Need to sort it in the code and pass the value in that field along with the column number.

Okay, I fought through a good amount of this and have gotten to the point where I can sort things. What I need to do now is take the following code and sort the elements in descending order. I don't know how to do that with the two arguments in the code:

Dim Cols(3) As Int16
Cols(0) = ColumnNumber + 1
Cols(1) = ColumnNumber + 2
Cols(2) = ColumnNumber + 3
Cols(3) = ColumnNumber + 4

Dim Vals(3) As Double
Vals(0) = xlsWorkSheet.Cells(r, ColumnNumber + 1).value
Vals(1) = xlsWorkSheet.Cells(r, ColumnNumber + 2).value
Vals(2) = xlsWorkSheet.Cells(r, ColumnNumber + 3).value
Vals(3) = xlsWorkSheet.Cells(r, ColumnNumber + 4).value

Array.Sort(Vals, Cols)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.