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:
If MyCell .Value= Like "Name" then
MyCell.Font.Bold = True
Else
MyCell.Font.Bold= False
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:
Range("A1").Select
ActiveCell.FormulaR1C1 = "Some Name"
With ActiveCell.Characters(Start:=1, Length:=5).Font
.Name = "HelveticaNeue LT 43 LightEx"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=6, Length:=4).Font
.Name = "HelveticaNeue LT 43 LightEx"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("C10").Select
End Sub
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