Consulting

Results 1 to 5 of 5

Thread: Solved: Make text in a cell bold

  1. #1

    Solved: Make text in a cell bold

    Hello,

    I am trying to make the text in an specific cell bold. The text is inside a table and for some reason every time I use a macro that copies from another sheet and pastes values here, conditional formation stops working. Actually the range that i set it to cover first splits in two to exclude the table.

    The words I want bold are " Systems", "Cookies", "Items"

    I am a total newbie to VBA I am trying to learn as I go, I tried to create a code but it gives me an error.

    Here is the code I have

    [VBA]Sub AddSystems(varColumns As String)


    Call ClearContents

    Sheets("Appendix Data").Range("A6:A406").Value = Sheets("Systems").Range(varColumns & 2, varColumns & 402).Value

    With Sheets("Appendix Data").Range("A1:A1000")
    .Find.Value = "Systems"
    .Font.Bold = True
    End With
    End Sub[/VBA]

    thanks for the help
    Feedback is the best way for me to learn


    Follow the Armies

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    When you copy, it will copy the format unless you code around it.

    You bold code will bold the whole range, not just a cell with Systems in it, as it is all encompassed within the with statement.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks,

    I used the macro recorder and i got this piece of code


    [VBA]Range("A1:A10000").Find(What:="Systems", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False).Activate
    Selection.Font.Bold = True[/VBA]


    But the thing is that

    1 it uses selection which i am trying to avoid ( it should speed up the macro)
    2 it bolds only the first instance of the word not the rest.

    I am really trying here but VBA is hard. I will go back to my book to try to find a solution. I tried to look it up on the web but there is no other thread regarding the matter.

    Thanks
    Feedback is the best way for me to learn


    Follow the Armies

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can use Excel search and replace

    [VBA]Sub UpdateData()

    Application.ReplaceFormat.Font.FontStyle = "Bold"
    Call enbolden(Range("A1:A10000"), "Systems")
    Call enbolden(Range("A1:A10000"), "Cookies")
    Call enbolden(Range("A1:A10000"), "Items")
    End Sub

    Private Function enbolden(rng As Range, ByVal lookup As String)

    rng.Replace What:=lookup, _
    Replacement:=lookup, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    MatchCase:=False, _
    SearchFormat:=False, _
    ReplaceFormat:=True
    End Function
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    this code works perfectly thanks a lot

    ::
    Feedback is the best way for me to learn


    Follow the Armies

Posting Permissions

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