Conditional Number Formatting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I need to number format a group of cells based on the number contained in
another cell. In other words, if the value in A1 is 1 I need to format A2 to
D2 as percent, if the value in A1 is 0 I need to format A2 to D2 as a number.

From, trying to figure out how t odo it I gathered that conditional
formatting will not be able to do it, and I don't know how to write a macro
to do it so any help will be appreciate it.
Thanks in advance.
Neda
 
one way:

Put this in your worksheet code module (right-click the worksheet tab an
choose View Code):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then _
Range("A2:D2").NumberFormat = _
IIf(Range("A1").Value = 1, "0%", "0.00")
End Sub


Adjust the formats as desired.
 
Works greatly.
Thanks.

JE McGimpsey said:
one way:

Put this in your worksheet code module (right-click the worksheet tab an
choose View Code):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then _
Range("A2:D2").NumberFormat = _
IIf(Range("A1").Value = 1, "0%", "0.00")
End Sub


Adjust the formats as desired.
 

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

Back
Top