Hello Rahulpandita,
Welcome to the Forum!
The attached workbook contains the macro shown here. It will format the data as you specified.
'Written: Decemeber 18, 2010
'Author: Leith Ross (www.excelforum.com)
Sub FormatData()
Dim BaseColor(1) As Integer
Dim ColorFlag As Long
Dim Group As Range
Dim HighLight(1) As Integer
Dim I As Long
Dim LastColumn As Long
Dim LastRow As Long
Dim N As Long
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Set Wks = Set Wks = Worksheets("Data")
LastColumn = Wks.Cells(1, Columns.Count).End(xlToLeft).Column
Set Rng = Wks.Range("A2", Wks.Cells(2, LastColumn))
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
I = 1
BaseColor(0) = 40
BaseColor(1) = 20
HighLight(0) = 44
HighLight(1) = 37
For Each Cell In Rng.Columns(1).Cells
N = N + 1
If Cell <> Cell.Offset(1, 0) Then
ColorFlag = Abs(ColorFlag) Mod 2
Set Group = Wks.Range(Rng.Cells(I, "A"), Rng.Cells(N, LastColumn))
Group.Interior.ColorIndex = BaseColor(ColorFlag)
Set Group = Wks.Range(Rng.Cells(I, "B"), Rng.Cells(N, LastColumn))
For R = 1 To Group.Rows.Count Step 2
Group.Rows(R).Cells.Interior.ColorIndex = HighLight(ColorFlag)
Next R
I = N + 1
ColorFlag = ColorFlag + 1
End If
Next Cell
End Sub
To Run the Macro...
To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
Bookmarks