Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Excel Sorting with Vb.net

I'm creating and manipulating an Excel spreadsheet from within my VB.net program. I'm using these imports:
Code
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel

I'm creating these objects:

Code
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

Initializing them:

Code
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)

After writing to the cells I'm sorting like this:
Code
myRange = oSheet.Range("A2", "H50" )
myRange.Select()
myRange.Sort(Key1:=myRange.Range("f1"), Order1:=XlSortOrder.xlDescending, Orientation:=XlSortOrientation.xlSortColumns)

Everything works fine at this point.  I've made some of the cells background color green in column H and now I want to sort on the cell background color.  What is the code to accomplish that?
since no one answered lol..

take a look at this; https://stackoverflow.com/questions/2365...ng-c-sharp

i dont really like linking sof links but couldnt find much on it, the example in that post seems to be what you're looking for, something like this?

PHP Code

<?php 
currentSheet
.Sort.SortFields.Clear()
    
currentSheet.Sort.SortFields.Add(DupesColumn, XlSortOn.xlSortOnCellColor, XlSortOrder.xlAscending)
    
currentSheet.Sort.SortFields(0).SortOnValue.Color = XlRgbColor.rgbRoyalBlue
    currentSheet
.Sort.SetRange(DupesColumn.CurrentRegion)
    
currentSheet.Sort.Header = XlYesNoGuess.xlYes
    currentSheet
.Sort.MatchCase = False
    currentSheet
.Sort.Orientation = XlSortOrientation.xlSortColumns
    currentSheet
.Sort.SortMethod = XlSortMethod.xlPinYin
    currentSheet
.Sort.Apply() 

give it a shot, if it doesnt work il take a look when im home


Possibly Related Threads...
Thread / Author Replies Views Last Post
by lucienhfMar 22, 2024 03:06 AM 4 241 Mar 22, 2024 03:06 AM
Last Post: lucienhf
[Python] by ThisBearScatJan 27, 2020 06:27 PM 16 341 Jan 27, 2020 06:27 PM
Last Post: Lindros
[Java] by xpgbeastMay 8, 2018 11:58 AM 3 155 May 8, 2018 11:58 AM
Last Post: deluxe