尝试根据使用 VBA 在相邻单元格上选择的货币设置单元格的数字格式。请参阅下面的示例。
到目前为止,我正在使用下面的代码,但我似乎无法使格式正确显示
Option Explicit
Public preValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim Rng As Range
Dim ccy As String
ccy = Range("A3").Value
pctFormat = "0.000%"
fxFormat = ccy + " " + pctFormat
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next
If Not Intersect(Target, Range("A2:A10")) Is Nothing Then
If Target.Value <> preValue And Target.Value <> "" Then
Application.EnableEvents = False
Cells(Target.Row, Target.Column + 1).NumberFormat = fxFormat
Application.EnableEvents = True
End If
End If
On Error GoTo 0
End Sub