Search code examples
vbaexcelfunctionfonts

Change Part of text font in Excel cell using vba


Hi I am trying to create a function to calculate milliohms (mOhms) my function is

Function mOhms(Current, Voltage)
mOhms = Format((Voltage / Current) * 1000, "00.00 m") & Chr(87)
End Function

with results being

40.00 mW (if cell values are 24 and 1 respectivly)

How do i get the W as (Ω) ohms symbol if i change the cell font style to Symbol m changes to micro (μ) symbol

i have tried paying with

With ActiveCell.Characters(Start:=Len(ActiveCell) - 1, Length:=1).Font
.FontStyle = "Symbol"
End With

Which results in "Circular reference error"s

Need some help to resolve this


Solution

  • Try using Unicode in place of the Chr(87)

    Function mOhms(Current, Voltage)
    mOhms = Format((Voltage / Current) * 1000, "00.00 m") & ChrW(&H2126)
    End Function