Thursday, October 20, 2011

Sort Data on the basis of Background Color

If you want to sort or arrange the data on the basis of background color.Snapshot Below-


Here is the code-

Sub sort_on_background_color()
Dim i As Long
' we will ADD Temp data to Col B and find the color index of all cells of columm a and , after that
' we will sort the data on the basis of color index and then we will delte all the temp data of col B
Sheets(1).Range("b1").Value = "Color Index"

' first we will get the color index for all the filled cells of cOL A IN Col B
For i = 2 To Sheets(1).Range("a1").End(xlDown).Row
Sheets(1).Cells(i, 2).Value = Sheets(1).Cells(i, 1).Interior.ColorIndex
Next i
Sheets(1).Range("a1:b" & Range("a1").End(xlDown).Row).Sort key1:=Sheets(1).Range("b:b"), order1:=xlAscending, Header:=xlYes
Sheets(1).Columns("b:b").Delete
Sheets(1).Cells(1, 1).Select
End Sub

Download Excel Macro File

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...