2017-08-01 162 views
3

我有這個VBA腳本,我不知道如何製作動態的粗體部分,所以公式將是=StripAccent(C2),=StripAccent(C3)等等,每個iVBA中的動態變量

For i = 2 To 10 
    Cells(i, 5) = "=StripAccent(Ci)" 
Next i 

我讀了雙引號,但它沒有在那裏工作。

回答

3

這是一個可能的解決方案:

Public Sub TestMe() 
    Dim i As Long 
    For i = 2 To 10 
     Cells(i, 5) = "=StripAccent(C" & i & ")" 
    Next i 
End Sub 

另一個是使用Cells(i,3)

編輯:如果您正在使用從這裏自定義函數 - Converting Special Characters into alphabet那麼這樣的事情能夠工作,以及(但不是作爲一個公式):

Public Sub TestMe() 
    Dim i As Long 
    For i = 2 To 10 
     Cells(i, 5) = StripAccent(Cells(i,3)) 
    Next i 
End Sub 
1
For i = 2 To 10 
    Cells(i, 5).Formula = "=StripAccent(C" & i & ")" 
Next i 
2

在你的情況,你不需要一個循環,你可以直接添加Formula到您的整個範圍,就像這樣:

Range(Cells(2, 5), Cells(10, 5)).Formula = "=StripAccent(C2)" 

或者,甚至「清潔工」:

Range("E2:E10").Formula = "=StripAccent(C2)" 
+0

@Vityata他在哪裏提到他需要循環?我認爲他希望按照「E」列中的行號拖動Fomrula –

+1

似乎合法。 – Vityata