Results 1 to 3 of 3

Thread: Loop through cells and bold

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    74

    Loop through cells and bold

    I currently have a macro that produces a grid with multiple names within each cell in the gird.

    I would like to create a macro that runs after the gridding macro that does these things:

    1. Loops back through the list of names and their data and determines if a quality about them is true or false, then I want it to switch over to the worksheet with the grid and bold their name, if the condition is false, I want to it leave it in regular text format.

    This is what I have so far, but obviously this will bold the entire cell, and not the individual names.

    VB Code:
    1. If MyCell .Value= Like "Name" then
    2. MyCell.Font.Bold = True
    3. Else
    4. MyCell.Font.Bold= False

  2. #2
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: Loop through cells and bold

    Don't know if it's of any use, but here's a macro bolding just part of a cell (just the word "Name" is set to bold).

    VB Code:
    1. Range("A1").Select
    2.     ActiveCell.FormulaR1C1 = "Some Name"
    3.     With ActiveCell.Characters(Start:=1, Length:=5).Font
    4.         .Name = "HelveticaNeue LT 43 LightEx"
    5.         .FontStyle = "Regular"
    6.         .Size = 10
    7.         .Strikethrough = False
    8.         .Superscript = False
    9.         .Subscript = False
    10.         .OutlineFont = False
    11.         .Shadow = False
    12.         .Underline = xlUnderlineStyleNone
    13.         .ColorIndex = xlAutomatic
    14.     End With
    15.     With ActiveCell.Characters(Start:=6, Length:=4).Font
    16.         .Name = "HelveticaNeue LT 43 LightEx"
    17.         .FontStyle = "Bold"
    18.         .Size = 10
    19.         .Strikethrough = False
    20.         .Superscript = False
    21.         .Subscript = False
    22.         .OutlineFont = False
    23.         .Shadow = False
    24.         .Underline = xlUnderlineStyleNone
    25.         .ColorIndex = xlAutomatic
    26.     End With
    27.     Range("C10").Select
    28. End Sub
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    74

    Re: Loop through cells and bold

    I just got this comment from a user in a Microsoft forum, but I can't really understand how to apply it to my code.

    Keep a record of who needs to be highlighted by name and location in the grid
    (or run it as a separate program)

    you can bold a part of a string with

    Sub BoldThe()
    s = "Running in the Woods is hard"
    i = InStr(1, s, "the", vbTextCompare)
    ActiveCell.Value = s
    ActiveCell.Characters(i, 3).Font.Bold = True
    ActiveCell.WrapText = True
    ActiveCell.EntireRow.AutoFit
    End Sub

    as a demonstration. The above is probably applicable for your second
    column. Pick a standard column width, just append your names with no
    chr(10) and when done, autofit the rows. The names won't necessarily be
    lined up in a columnar fashion. If you need columnar, then you two column
    approach seems good. You might do better with a mono-spaced font like
    courier new. Also using a smaller font size might help.

    --
    Regards,
    Tom Ogilvy

Posting Permissions

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



Click Here to Expand Forum to Full Width