set font size by cell value

bak

New Member
Joined
Mar 3, 2011
Messages
26
I'm trying to set a macro to change a font size for every cell in range("A-A"). If the value in that cell starts with: "chapter" then change the font size to 20.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try

Code:
Sub size()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If LCase(Range("A" & i).Value) Like "chapter*" Then Range("A" & i).Font.size = 20
Next i
End Sub
 
Upvote 0
I'm trying to set a macro to change a font size for every cell in range("A-A"). If the value in that cell starts with: "chapter" then change the font size to 20.

How about

Code:
Sub bak()
Dim a As Range
Dim c As Range
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

Set a = Range("A1:A" & lr)

For Each c In a

If Left(c, 7) = "chapter" Then c.Font.Size = 20

Next c

End Sub
 
Upvote 0
Hi CoG

I am trying to slightly change your code.

In the line setting type size I want to also include italics and underline. Have tried several combinations (using code generated by recorder) to add to the code after:

............20,Font.Italic = True etc
but not working. Do I use a . or a comma, or something different for the second and third format items.

Also how do I add another argurment. eg we have "chapter' now, but I need "chapter1" and "chapter2" etc, each has a different setting. eg Size 16 Bold and Size 12 Bold

Your comments would be appreciated.
Thanks

Charlie Harris
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top