Formatting Font in a range based on reference range

Patrick3001

New Member
Joined
Oct 28, 2010
Messages
4
Hello all,

I'm sure this is very simple but I'm stuck.

I have a range of cells - L1:L1000 all of which need to have their font changed if the respective cell in T1:T1000 = "Caution".

I've got conditional formatting for background shading, but thats no good for people using black and white printers hence the font change.

So far I'm at:

Private Sub Worksheet_Calculate()
If (Range("T1")) = "Caution" Then
Range("L1").Font.Name = "Impact"
Else
Range("L1").Font.Name = "Calibri"
End If


This seems to work fine for "L1", I just don't know how to make it work through each row up to L1000.

I'm using excel 2010, but file has to also run in 2003.

Any help would be greatly appreciated.

Thanks
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,693
Office Version
365
Platform
Windows
Welcome to the board!

Try;
Code:
Private Sub Worksheet_Calculate()
    Dim rngCell As Range
    
    For Each rngCell In Range("L1:L1000")
        If rngCell.Text = "Caution" Then
            rngCell.Font.Name = "Impact"
        Else
            rngCell.Font.Name = "Calibri"
        End If
    Next rngCell
End Sub
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
Try

Code:
Private Sub Worksheet_Calculate()
Dim i As Long
For i = 1 To 1000
    If Range("T" & i).Value = "Caution" Then
        Range("L" & i).Font.Name = "Impact"
    Else
        Range("L" & i).Font.Name = "Calibri"
    End If
Next i
End Sub
 

WinteE

Well-known Member
Joined
Apr 8, 2007
Messages
605
Try this :

Code:
Sub TestFont()

    For Each c In Range("l1:l30")
        If Range("T" & c.Row) = "Caution" Then
            c.Font.Name = "Impact"
        Else
            c.Font.Name = "Calibri"
        End If
    Next c

End Sub
Success
Erik
 

Patrick3001

New Member
Joined
Oct 28, 2010
Messages
4
Erik, Peter,

Thank you both so much - I've checked, and both of your responses work exactly as requested.

Thank you again.


Patrick
 

Forum statistics

Threads
1,081,543
Messages
5,359,431
Members
400,526
Latest member
Brook1083

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top