目的:条件格式 - 字体大小
如果K19 ="首付款来源:"然后K19字体10,否则12
如果K21 ="金额:"然后是K21字体10,否则为12。
尝试:
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

此代码有效,但我不知道如何添加K21。
另一个想法:
如果B3 ="购买"然后K19,K21字体大小10,否则12。
任何一个都可以工作,我对VBA没有经验。
非常感谢任何帮助
答案 0 :(得分:1)
当B3成为购买时,解决了更改K19和K21的选项。注意:这仅在B3更改时触发。
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