2016-11-16 171 views
2

我有一個vba代碼問題。我不知道爲什麼,但它消除了公式前面的等號...也許有人知道如何解決它?Excel VBA從公式中刪除等號

enter image description here

這裏是Excel工作表的全部源代碼:

Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim c As Range 
    For Each c In Target.Cells 
     If Not Intersect(c, Range("X:AI")) Is Nothing Then 
      If c > Range("H" & c.Row).Value Or c < Range("G" & c.Row).Value Then 
       c.Font.ColorIndex = 3 
      ElseIf c <= Range("H" & c.Row).Value And c >= Range("G" & c.Row).Value Then 
       c.Font.ColorIndex = 10 
      End If 


      Dim frml1 As String 
      Dim frml2 As String 
      frml1 = "LARGE(X" & c.Row & ":AI" & c.Row & ";1)" 
      frml2 = "SMALL(X" & c.Row & ":AI" & c.Row & ";1)" 
      Range("AK" & c.Row).Value = "=AVERAGE(X" & c.Row & ":AI" & c.Row & ")" 
      Range("AJ" & c.Row).Value = "=" & frml1 & " - " & frml2 
     ElseIf Not Intersect(c, Range("AL:AM")) Is Nothing Then 
      If c > Range("K" & c.Row).Value Or c < Range("J" & c.Row).Value Then 
       c.Font.ColorIndex = 3 
      ElseIf c <= Range("K" & c.Row).Value And c >= Range("J" & c.Row).Value Then 
       c.Font.ColorIndex = 10 
      End If 
     ... 
     ElseIf Not Intersect(c, Range("AU:AU")) Is Nothing Then 
      If c > Range("Q" & c.Row).Value Or c < Range("P" & c.Row).Value Then 
       c.Font.ColorIndex = 3 
      ElseIf c <= Range("Q" & c.Row).Value And c >= Range("P" & c.Row).Value Then 
       c.Font.ColorIndex = 10 
      End If 
     ElseIf Not Intersect(c, Range("AY:AY")) Is Nothing Then 
      If c > Range("T" & c.Row).Value Or c < Range("S" & c.Row).Value Then 
       c.Font.ColorIndex = 3 
      ElseIf c <= Range("T" & c.Row).Value And c >= Range("S" & c.Row).Value Then 
       c.Font.ColorIndex = 10 
      End If 
     End If 
    Next c 
End Sub 

回答

3

你 「;」在你的公式中,而不是「,」。也許是因爲你的公式錯誤地將其刪除。

+0

「,」或「;」是區域設置中的設置。基本上取決於你的語言 – Andreas

+0

Excel分隔符取決於語言...例如,在excel中使用丹麥語LP,那麼有必要用分號分隔,因爲逗號已經用於十進制分隔,而不是英語中的千位分隔符。 – 2016-11-16 09:06:39

+0

每天學習新東西! – ClintB

1

,如果你在Excel編碼這個樣子,這是一個好主意,要注意以下事項:

?application.PathSeparator 
?application.DecimalSeparator 
?Application.International(xlFormula) 

把它們寫在VB編輯器的直接窗口,就看你的結果。然後你可以在VBA代碼中使用它們,這在德國和美國都可以說。