Strictly speaking, the superscript issue is a different problem. However, the reason it is not working, I think, is because the formula is put into multiple cells. Hence, it seems to me that you can't use the Worksheet Change event handler to format the cells in this instance. The WSC event handler will work if you manually type, for example, 9+10, in a cell which will give you 9+10
Anyway, the following code seems to do the job:
Sub APlusB()
Range("F8").FormulaR1C1 = _
"=IF(COUNTIF(RC[-2]:RC[-1],""AB"")=2,""AB"",IF(SUM(RC[-2]:RC[-1])=0,"""",SUM(RC[-2]:RC[-1])))"
Range("f8").Copy
Range("f9:f100").Select
ActiveSheet.Paste
Range("f8:f100").Copy
Range("f8:f100").PasteSpecial Paste:=xlPasteValues
MsgBox "Done", 64
End Sub
Sub Average()
Range("g8").FormulaR1C1 = _
"=IF(RC[-1]=""AB"",""AB"",IF(RC[-1]="""","""",IF(RC[-1]/2=0,"""",ROUND(RC[-1]/2,0))))"
Range("g8").Copy
Range("g9:g100").Select
ActiveSheet.Paste
Range("g8:g100").Copy
Range("g8:g100").PasteSpecial Paste:=xlPasteValues
MsgBox "Done", 64
End Sub
Sub Total()
Dim cell As Range
Dim iStart As Integer
Dim iLength As Integer
Dim lLR As Long
Dim rRangeToFormat As Range
lLR = Range("D" & Rows.Count).End(xlUp).Row
Set rRangeToFormat = Range("I8:I" & lLR)
Application.ScreenUpdating = False
Application.EnableEvents = False
With rRangeToFormat
.FormulaR1C1 = _
"=IF(RC[-2]="""","""",IF(RC[-1]=0,RC[-2],CONCATENATE(RC[-2],""+"",RC[-1])))"
.Value = .Value
End With
Application.EnableEvents = True
For Each cell In rRangeToFormat
If InStr(1, cell, "+") > 0 Then
iStart = InStr(1, cell, "+")
iLength = Len(cell) - iStart + 1
With cell.Characters(Start:=iStart, Length:=iLength).Font
.Superscript = True
.ColorIndex = 3
End With
Else
With cell.Font
.FontStyle = "Regular"
.Superscript = False
.ColorIndex = xlAutomatic
End With
End If
Next 'cell
Application.ScreenUpdating = True
MsgBox "Done", 64
End Sub
See the updated example workbook.
Regards, TMS
Bookmarks