ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How do I have a macro format cells while recording? (https://www.excelbanter.com/excel-worksheet-functions/25892-how-do-i-have-macro-format-cells-while-recording.html)

TD

How do I have a macro format cells while recording?
 
I am attempting to record a macro similar to the one below, however at the
end of the data/sort I want to include cell formatting so that the top three
automatically appear in green, and the fourth automatically appears in red.
Is this possible?

Range("A4:H15").Select
Selection.Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Bob Phillips

Set rng = Range("A4:H15")
rng.Sort Key1:=rng.Cells(1,1),Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
rng.cells.Interior.Colorindex = xlColorindexNone
For each cell in rng
If cell.Value = Application.Small(rng,1) Or cell.Value =
Application.Small(rng,2) Or _
cell.Value = Application.Small(rng,3) Then
cell.Interior.Colorindex = 10
ElseIf cell.Value = Application.Small(rng,4)Then
cell.Interior.Colorindex = 3
End If
Next cell

End Sub

--
HTH

Bob Phillips

"TD" wrote in message
...
I am attempting to record a macro similar to the one below, however at the
end of the data/sort I want to include cell formatting so that the top

three
automatically appear in green, and the fourth automatically appears in

red.
Is this possible?

Range("A4:H15").Select
Selection.Sort Key1:=Range("A4"), Order1:=xlAscending,

Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub





All times are GMT +1. The time now is 01:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com