PDA

View Full Version : Excel VBA: Format and change cell value based on specific values in cell



needhelpalwa
08-31-2018, 06:04 AM
I would like the below to change the value of the particular cell to "Rank" if two consecutive cells in the column are "#Name"
In addition, it would be helpful if the formatting of the cell could be red and font color white, while the value in the preceding cell would be nothing, and color blue

This is what I wrote but it isn't working, really appreciate guidance-

Sub FormatRankColmn()
'
' FormatRankColmn Macro
'

'
Dim cell As Range

ForEach cell In Range("D1:250").SpecialCells(xlCellTypeConstants)

If cell.Offset(-1,0).Value ="#NAME"Then
If cell.Value ="#Name"Then
Range(cell).Value ="Rank"
EndIf
EndIf
Next
EndSub