ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro for: If cell has 4 characters, make cell red (https://www.excelbanter.com/excel-programming/356802-macro-if-cell-has-4-characters-make-cell-red.html)

Sandeman[_11_]

Macro for: If cell has 4 characters, make cell red
 

I'd like a macro to identify cells with only 4 characters (i.e. a yea
like 1989) and if the cell has only 4 characters, to make th
characters in the cell to the right of it bold red. For example, i
cell A29 is 1933, the characters in cell B29 should be in bold red.

Thanks for your help

--
Sandema
-----------------------------------------------------------------------
Sandeman's Profile: http://www.excelforum.com/member.php...fo&userid=3244
View this thread: http://www.excelforum.com/showthread.php?threadid=52530


Carim

Macro for: If cell has 4 characters, make cell red
 
Hi Sandeman,

Give a try to following :
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Cell As Range
Set Target = Range("A1:A50")
If Target Is Nothing Then
Exit Sub
Else
For Each Cell In Target
If Len(Cell.Value) = 4 Then
Cell.Offset(0, 1).Range("A1").Interior.ColorIndex = 3
End If
If Len(Cell.Value) < 4 Then
Cell.Offset(0, 1).Range("A1").Interior.ColorIndex = xlNone
End If
Next Cell
End If
End Sub


HTH
Carim


Sandeman[_12_]

Macro for: If cell has 4 characters, make cell red
 

Wonderful. Thank you Carim

--
Sandema
-----------------------------------------------------------------------
Sandeman's Profile: http://www.excelforum.com/member.php...fo&userid=3244
View this thread: http://www.excelforum.com/showthread.php?threadid=52530



All times are GMT +1. The time now is 09:12 PM.

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