ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   associate cell format (https://www.excelbanter.com/excel-programming/375999-associate-cell-format.html)

massi[_2_]

associate cell format
 
Hi,
I would like to associate a particular format to a cell depending on the
text contained by the cell next to it. so if for example cell A1 has date and
time i would like to have a particular format in B1; if A2 has number of
people i would kie to have in B2 an other type of format.
is that possible?

Bob Phillips

associate cell format
 
One way

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H10" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Select Case Target.Value
Case 1: Target.Offset(0, 1).NumberFormat = "dd mmm yyyy"
Case 2: Target.Offset(0, 1).NumberFormat = "#,##0.00"
Case 3: Target.Offset(0, 1).NumberFormat = "#,##0"
'etc
End Select
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"massi" wrote in message
...
Hi,
I would like to associate a particular format to a cell depending on the
text contained by the cell next to it. so if for example cell A1 has date

and
time i would like to have a particular format in B1; if A2 has number of
people i would kie to have in B2 an other type of format.
is that possible?





All times are GMT +1. The time now is 04:05 AM.

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