![](/img/trans.png)
[英]Excel VBA : assign formula to multiples dynamic range table in same sheet
[英]VBA Excel, assign formula to row in range
我是VBA的新手,想問一下您是否可以幫助我。 我有這個VB6代碼:
For i = 2 To rowCount - 2
' Fill Ji with a formula(=MID(Fi,11,9)) and apply format.
Set oRng = oSheet.Range(Cells(i, 10), Cells(rowCount - 2, 10))
**oRng.formula = "=MID(Cells(i,6),11,9)"**
oRng.NumberFormat = "[$-F400]hh:mm:ss"
Next i
我想為范圍分配一個公式。嘗試過此代碼,但是分配公式時出現問題。 它不會將Cell(i,6)識別為Cell,而是將其識別為字符串“ Cell(i,6)”。 誰能幫我?
您不希望循環,因為您要立即將公式放入所有單元格中:
' Fill Ji with a formula(=MID(Fi,11,9)) and apply format.
Set oRng = oSheet.Range(oSheet.Cells(2, 10), oSheet.Cells(rowCount - 2, 10))
oRng.formulaR1C1 = "=MID(RC6,11,9)+0"
oRng.NumberFormat = "[$-F400]hh:mm:ss"
注意:我在公式中添加了+0,可將文本轉換為真實時間值。
僅當您想要相對引用時,才嘗試"=MID(" & Cells(i,6).Address(False,False) &",11,9)"
包括地址部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.