automatically format cell based on content of another cell

G

Guest

I am trying to automatically format a cell to display its contents in either
a date or number format based on which letter is displayed in another cell in
the same row. I.E. cell 5a value is M, I need cell 5f to be in MMMYY
format.
 
B

Bernie Deitrick

You would need to use the Change event: copy the code below, right -click
the sheet tab, select "View Code" and paste the code into the window that
appears. I have included a second condition (N) to show how to do multiple
formats based on entries in column A.

HTH,
Bernie
MS Excel MVP


Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
For Each myCell In Intersect(Target, Range("A:A"))
If UCase(myCell.Value) = "M" Then
Cells(myCell.Row, 6).NumberFormat = "MMM YY"
End If
If UCase(myCell.Value) = "N" Then
Cells(myCell.Row, 6).NumberFormat = "0.00"
End If
Next myCell
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top