Conditional Text Formatting

R

routeram

Hi,

Is there a way to do this?

B1 - F cm-2 (-2 superscripted)
B2 - C cm-2 (-2 superscripted)

B3 must contain B1 or B2 depending on a condition. I want to preserv
the formatting (the superscripts) which the if statement does not do.

Thanks
 
R

routeram

How to do with macros?

Using the worksheet calculate event? How to do so efficiently?
 
D

Dave Peterson

It depends on what's changing and how it's changing.

Here my trigger cell was A1 of the same sheet and it was changing by the user
typing something in.

rightclick on the worksheet tab and select view code. Paste this in the window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim ToCell As Range
Dim FromCell As Range
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then Exit Sub

Set ToCell = Me.Range("B3")

If Target.Value < 3 Then
Set FromCell = Me.Range("B1")
Else
Set FromCell = Me.Range("b2")
End If

Application.EnableEvents = False
FromCell.Copy _
Destination:=ToCell
Application.EnableEvents = True

End Sub
 
Top