Consulting

Results 1 to 6 of 6

Thread: Trying to make specific cell contents bold

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location

    Trying to make specific cell contents bold

    I have the following in my sub for which I would like the word 'Highlight' to be bold.

    If Application.WorksheetFunction.CountA(Sheets("Highlight Markers").Cells) <> 0 Then
            
            Sheets("Highlight Markers").Range("A1") = "Highlight"
            Sheets("Highlight Markers").Range("A2") = "These are the rest :-"
            
        ElseIf Application.WorksheetFunction.CountA(Sheets("Highlight Markers").Cells) = 0 Then
            Sheets("Highlight Markers").Range("A1") = "Highlight"
            Sheets("Highlight Markers").Range("A2") = "Nothing to report that is of any noteworthiness"
    End If
    If I use
    Sheets("Highlight Markers").Range("A1").Font.Bold = "Highlight"
    then nothing happens. If I use
    Sheets("Highlight Markers").Range("A1") = "Highlight"
    Selection.Font.Bold = True
    then everything is made bold.

    Thanks!
    Steve

  2. #2
    VBAX Contributor rollis13's Avatar
    Joined
    Jun 2013
    Location
    Cordenons
    Posts
    146
    Location
    Something wrong here:
    Sheets("Highlight Markers").Range("A1").Font.Bold = "Highlight"
    
    should be:
    
    Sheets("Highlight Markers").Range("A1").Font.Bold = True
    In the second case you are making 'Selection.' bold, but what have you selected ?
    Sheets("Highlight Markers").Range("A1") = "Highlight"
    fills a cell, doesn't select it.

  3. #3
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    I used option one, but this did not input the word "Highlight", so I ended up with a completely empty cell which also did not have bold assigned to it.

    I was hoping that the selection would be focussed on the Range A1.

    I have also tried this, which didn't do anything.

    Sheets("Highlight Markers").Range("A1").Font.Bold("Highlight") = True

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,871
    With Sheets("Highlight Markers").Range("A1")
      x = InStr(1, .Value, "highlight", vbTextCompare)
      If x > 0 Then .Characters(Start:=x, Length:=9).Font.FontStyle = "Bold"
    End With
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Contributor rollis13's Avatar
    Joined
    Jun 2013
    Location
    Cordenons
    Posts
    146
    Location
    This is the only other way I know:
    With Sheets("Highlight Markers")    
        .Range("A1") = "Highlight"
        .Range("A1").Font.Bold = True
    End With

  6. #6
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    My thanks to both p45cal and rollis13!

    Both alternatives work, although p45cal's version allows the specification of how many characters to make bold counting from the left.

    Many thanks!
    Steve

Posting Permissions

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