简体   繁体   中英

VBA - Conditional Format (Font Size)

Purpose: Conditional Formatting - Font Size

If K19 = "Downpayment Source:" Then K19 font 10, else 12

If K21 = "Amount:" Then K21 font 10, else 12.

Trying:

 Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Set Target = ActiveSheet.Range("K19") If Target = "Downpayment Source:" Then With ActiveSheet.Range("K19").Font .Name = "Arial" .Size = 10 End With Else With ActiveSheet.Range("K19").Font .Name = "Arial" .Size = 12 End With Exit Sub End Sub

This code works, but I don't know how to add K21.

Another Idea:

If B3="Purchase" then K19, K21 font size 10, else 12.

Either one would work, I'm just not that experienced with VBA.

Any help is greatly appreciated

Addresses the option of changing K19 and K21 when B3 becomes Purchase. Note: This only triggers if B3 changes.

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B3")) Is Nothing Then
        If Target.Value = "Purchase" Then
            With ActiveSheet.Range("K19").Font
                .Name = "Arial"
                .Size = 10
            End With
            With ActiveSheet.Range("K21").Font
                .Name = "Arial"
                .Size = 10
            End With
        Else
            With ActiveSheet.Range("K19").Font
                .Name = "Arial"
                .Size = 12
            End With
            With ActiveSheet.Range("K21").Font
                .Name = "Arial"
                .Size = 12
            End With
        End If
    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM