+ Reply to Thread
Results 1 to 6 of 6

format a string as bold

Hybrid View

danman1453 format a string as bold 06-04-2012, 09:48 AM
danman1453 Re: format a string as bold 06-04-2012, 11:22 AM
danman1453 Re: format a string as bold 06-04-2012, 12:20 PM
GCW esq Re: format a string as bold 06-04-2012, 12:29 PM
danman1453 Re: format a string as bold 06-04-2012, 01:26 PM
GCW esq Re: format a string as bold 06-04-2012, 08:09 PM
  1. #1
    Registered User
    Join Date
    06-04-2012
    Location
    https://t.me/pump_upp
    MS-Off Ver
    Excel 2010
    Posts
    4

    Question format a string as bold

    Looks like a nice community here. Hopefully somebody can lend me a hand on this.

    Here is my goal:
    I have a column with 3 tri-state text strings in it. Example: |1 2 3| or |1 2 3| or | 2 3|
    So, 1, 2, and 3 all have the option of being null(not present), normal, and bold.

    I have set the inital value of each as normal text, without any formatting.

    I have tried the following code, without much success. I keep getting Invalid Qualifier errors.

    Public CharcoalText As String
    
    
    
    Function Charcoal_Check()
    CharcoalText = "AR G F"
    
    Dim AR_Text As String
    Dim GRAN_Text As String
    Dim FINE_Text As String
    
    AR_Text = "AR "
    GRAN_Text = "G"
    FINE_Text = " F"
    CharcoalText = AR_Text & GRAN_Text & FINE_Text
    
    If AR_NU Then AR_Text = "  "
    If AR_P Then
        With AR_Text.Characters(Start:=1, Length:=3)
            .FontStyle = "Bold"
        End With
    If G_NU Then GRAN_Text = " "
    If G_P Then GRAN_Text.Font.bold = True
    If F_NU Then FINE_Text = "  "
    If F_P Then FINE_Text.Font.bold = True
    
    CharcoalText = AR_Text & GRAN_Text & FINE_Text
    
    
    
    End Function
    I am getting the error highlighting AR_Text. in "With AR_Text.Characters....."

    If any further info is needed, feel free to ask.

  2. #2
    Registered User
    Join Date
    06-04-2012
    Location
    https://t.me/pump_upp
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: format a string as bold

    As a smaller question, how about this:
    How can I set the string stored in 'AR_Text' as bold upon a userform checkbox change?
    Last edited by danman1453; 06-04-2012 at 12:20 PM.

  3. #3
    Registered User
    Join Date
    06-04-2012
    Location
    https://t.me/pump_upp
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: format a string as bold

    I made the following changes, and got halfway there...

    Public CharcoalText As String
    Public AR_Text As String
    Public GRAN_Text As String
    Public FINE_Text As String
    
    
    
    
    Function Charcoal_Check()
    AR_Text = "AR "
    GRAN_Text = "G"
    FINE_Text = " F"
    
    If AR_NU Then AR_Text = " "
    If AR_P Then AR_Text = "<b>AR </b>"
    If G_NU Then GRAN_Text = " "
    If G_P Then GRAN_Text = "<b>G</b>"
    If F_NU Then FINE_Text = " "
    If F_P Then FINE_Text = "<b> F</b>"
    
    CharcoalText = AR_Text & GRAN_Text & FINE_Text
    
    End Function
    Now, it shows correctly in my column, but the bold tags are there too.

  4. #4
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: format a string as bold

    Not sure exactly what you're trying to do, but you can try something like this.
    You can do it without the WITH statement, but I have included it (commented out) in case you want it.
    It assumes your data ("AR ", "G" and " F") are in cells A1:A3.
    It just changes everything to bold, so you would have to work out what you want to do from there.

    Dim MyStuff As Range
    Set MyStuff = Range("A1:A3")
    For Each MyStuff In Cells.SpecialCells(xlConstants, xlTextValues)
    'With MyStuff.Characters(Start:=1, Length:=3).Font
        '.FontStyle = "Bold"
        MyStuff.Characters(Start:=1, Length:=3).Font.FontStyle = "Bold"
    'End With
    Next

  5. #5
    Registered User
    Join Date
    06-04-2012
    Location
    https://t.me/pump_upp
    MS-Off Ver
    Excel 2010
    Posts
    4

    Talking Re: format a string as bold

    Got it
    Public lLastRow As Long
    Public CharcoalText As String
    Public AR_Text As String
    Public GRAN_Text As String
    Public FINE_Text As String
    Public LoadText As String
    Public OvenText As String
    
    
    
    
    Function Charcoal_Check()
    AR_Text = "AR "
    GRAN_Text = "G"
    FINE_Text = " F"
    
    If AR_NU Then AR_Text = "   "
    
    If G_NU Then GRAN_Text = " "
    
    If F_NU Then FINE_Text = "  "
    
    
    CharcoalText = AR_Text & GRAN_Text & FINE_Text
    
    
    
    End Function
    Function Ch_Txt_Bold()
    If AR_P = True Then
    ActiveSheet.Cells(lLastRow + 6, 3).Select
    With ActiveCell.Characters(Start:=1, Length:=3).Font
        .FontStyle = "Bold"
    End With
    End If
    If G_P = True Then
    ActiveSheet.Cells(lLastRow + 6, 3).Select
    With ActiveCell.Characters(Start:=4, Length:=2).Font
        .FontStyle = "Bold"
    End With
    End If
    If F_P = True Then
    ActiveSheet.Cells(lLastRow + 6, 3).Select
    With ActiveCell.Characters(Start:=6, Length:=1).Font
        .FontStyle = "Bold"
    End With
    End If
    End Function
    
    Function LoadCheck()
    If LD_LOW = True Then LoadText = "LOW"
    If LD_MED = True Then LoadText = "MED"
    If LD_HIGH = True Then LoadText = "HIGH"
    End Function
    Function OvenCheck()
    If FrontOvenBox = True Then OvenText = "FRONT"
    If AllOvenBox = True Then OvenText = "ALL"
    End Function
    
    
    
    Sub Add_Button_Click()
    
    UserForm1.Charcoal_Check
    UserForm1.LoadCheck
    UserForm1.OvenCheck
    
    lLastRow = ActiveSheet.ListObjects("Table1").ListRows.Count
    ActiveSheet.Cells(lLastRow + 6, 1).Value = UserForm1.CodeText.Value
    ActiveSheet.Cells(lLastRow + 6, 2).Value = UserForm1.GradeText.Value
    ActiveSheet.Cells(lLastRow + 6, 3).Value = CharcoalText
    UserForm1.Ch_Txt_Bold
    ActiveSheet.Cells(lLastRow + 6, 4).Value = LoadText
    ActiveSheet.Cells(lLastRow + 6, 5).Value = OvenText
    ActiveSheet.Cells(lLastRow + 6, 6).Value = UserForm1.CommentsText.Value
    
    ' Module1.Sort
    
    End Sub
    
    
    
    
    
    
    
    Private Sub CancelButton_Click()
    Unload UserForm1
    End Sub
    
    Private Sub Done_Button_Click()
    Unload UserForm1
    End Sub
    Works perfect!

    I just needed a sounding board... Thanks.

  6. #6
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: format a string as bold

    Nice work.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1