Locking format when sorting

nerdle

New Member
Joined
Aug 6, 2010
Messages
4
I am attempting to make a spreadsheet with a list that will sort the information in a drop down menu. The problem I am having is that I want every other row to be gray or white and I want the alternating colors to remain once sorted. However, as is, the colors move with each row.

I've seen it done but I haven't been able to find how to do it.

Please help,

Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
That works except for the cells with text in them. For whatever reason they are still not working correctly. Any ideas?
 
Upvote 0
Try:
Code:
Private Sub FillOnlyOddRows()
    Dim n As Long
    Dim c As Long
 
    Application.ScreenUpdating = False
 
    For c = 2 To Range("A" & Rows.count).End(xlUp).Row
 
        If Rows(c).Hidden = False Then
            n = n + 1
 
            If n Mod 2 = 1 Then
                Rows(c).Interior.Color = RGB(220, 246, 255)
            Else
                Rows(c).Interior.Color = vbWhite
            End If
 
        End If
 
    Next c
 
    Application.ScreenUpdating = True
 
End Sub
 
Private Sub Worksheet_Change()
 
     Call FillOnlyOddRows
 
End Sub
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
    Call FillOnlyOddRows
 
End Sub
 
Upvote 0
I apologize for needing my hand held as I am a newb to this level of excel but I put the code into the Visual Basic Editor under its own module. I tried to access it through Macros but that was wrong so how do I use it?

Thanks again
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,217
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top