Two different fonts in one cell using excel vba

0 votes

In order to put a degree symbol after existing data in a cell, I consequently created a macro button to my ribbon. Also, I wanted to create a button that would add a check mark. Wingdings 2 converts "P" to a checkmark, according to my research. I can't figure out how to add the Wingdings 2 checkmark and keep the font of my current data without changing the font of the entire cell to Wingdings 2.

Sub Add_check()

Dim cellinfo As String
Dim cellinfoplus As String

'Grab existing content
cellinfo = ActiveCell.Value

'Change the "P" to a checkmark
ActiveCell.Value = "P"
    With Selection.Font
        .Name = "Wingdings 2"
    End With
'Save the checkmark into variable
cellinfoplus = ActiveCell.Value

'Concatenate variables
ActiveCell.Value = cellinfo + cellinfoplus

End Sub

I looked through this post on Mr. Excel but couldn't understand how to modify it and the youtube videos were taken down.

Apr 10, 2023 in Others by narikkadan
• 63,420 points
542 views

1 answer to this question.

0 votes

Public Sub add_degree_symbol()
   ActiveCell.Value = ActiveCell.Value & "°"
End Sub

Public Sub addCheck()
   With ActiveCell
      .Value = .Value & "P"
      .Characters(Len(.Value), 1).Font.Name = "Wingdings 2"
   End With
End Sub

and a sub for adding any symbols at start or at end (default)

Public Sub addSymbols(Optional addAny As String = "P", Optional atStart As Boolean = False, Optional fontName As String = "Wingdings 2")
   Dim ln As Integer, lnany As Integer

   With ActiveCell
      ln = Len(.Value)
      lnany = Len(addAny)
      If atStart Then
         .Value = addAny & .Value
         .characters(1, lnany).Font.Name = fontName
      Else
         .Value = .Value & addAny
         .characters(Len(.Value), lnany).Font.Name = fontName
      End If
   End With
End Sub

Sub helper()
   Call addSymbols("P ", True)
End Sub

And another version to toggle the symbols

Public Sub toogleSymbols(Optional addAny As String = "P", Optional atStart As Boolean = False, Optional fontName As String = "Wingdings 2")
   Dim ln As Integer, lnany As Integer

   With ActiveCell
      ln = Len(.Value)
      lnany = Len(addAny)
      If atStart Then
         If Mid(.Value, 1, lnany) = addAny Then
            fontName = .Characters(lnany + 1, 1).Font.Name
            .Value = Right(.Value, ln - lnany)
            .Characters(1, ln - lnany).Font.Name = fontName
         Else
            .Value = addAny & .Value
            .Characters(1, lnany).Font.Name = fontName
         End If
      Else
         If Right(.Value, lnany) = addAny Then
            .Value = Left(.Value, ln - lnany)
         Else
            .Value = .Value & addAny
            .Characters(Len(.Value) - 1, lnany).Font.Name = fontName
         End If
      End If
   End With
End Sub

Sub callToogleSymbols()
   Call toogleSymbols("P ", True)
End Sub
answered Apr 10, 2023 by Kithuzzz
• 38,010 points

Related Questions In Others

0 votes
1 answer

Excel formula for searching two text in one cell and return values based on the result

You can include a second IF within ...READ MORE

answered Oct 10, 2022 in Others by narikkadan
• 63,420 points
954 views
0 votes
1 answer

Activating a Specific Cell in Excel Using VBA Results to Error 400

I think you trying to select cells(4, ...READ MORE

answered Dec 27, 2022 in Others by narikkadan
• 63,420 points
337 views
0 votes
1 answer

Is there a way to test a formula result in excel and type it only once, all within one cell and not using a user defined function?

Use the Let function: =LET(Value,A1+B2+C4+G3+B4,IF(Value>10,"No",Value)) I hope this helps ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,420 points
384 views
0 votes
1 answer

Excel VBA userform paste text in expanded format (not just to one cell)

It should work if you simply supply ...READ MORE

answered Jan 21, 2023 in Others by narikkadan
• 63,420 points
386 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
876 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,183 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
480 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
731 views
0 votes
1 answer

Combine Two Formulas in Separate Cells Into One Cell

Use the openpyxl module in Python to do that, ...READ MORE

answered Mar 26, 2023 in Others by Kithuzzz
• 38,010 points
501 views
0 votes
1 answer

How to split columns into two sub columns under their parent column using python in excel

Use str.split: df[['pre', 'post']] = df['Column A'].str.split(r'\s*-->\s*', expand=True) print(df) # Output ...READ MORE

answered Apr 7, 2023 in Others by Kithuzzz
• 38,010 points
1,147 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP