2013-06-05 56 views
0

尝试使用VBA根据在相邻单元格上选择的货币设置单元格的数字格式。见下面的示例。基于在相邻单元格上给出的信息的单元格的数字格式(VBA)

enter image description here

到目前为止,我使用下面的代码,但我似乎无法让格式正确显示

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 

回答

1

你可以试试这个选项设置你的fxFormat variable

fxFormat = "[$" & ccy & "] 0.000%" 
1

也许是:

fxFormat = chr(34) & ccy & chr(34) & " " & pctFormat 
+0

这个解决方案也可以工作!有没有办法让我也可以给你一些答案? – macutan

+0

我不知道 - 我只是在这里待了几天! – JosieP

+1

@macutan upvote away!这是信用没有复选标记 – Brad

相关问题