標題:
[發問]
如何用陣列方式設定字體顏色?
[打印本頁]
作者:
justintoolbox
時間:
2015-7-12 20:09
標題:
如何用陣列方式設定字體顏色?
各位前輩大家好,
利用陣列的方式在儲存格上面填上數值是可以做到的。
但如何利用陣列方式設定字體顏色?
用底下的代碼,在設定字體顏色時候會出現問題,
想請問應該如何修正語法才能利用陣列方式順利設定字體顏色?謝謝。
Sub Ex()
Dim Ar(1 To 2, 1 To 1) As Variant, Cr(1 To 2, 1 To 1) As Variant
Ar(1, 1) = "A": Ar(2, 1) = "B"
Cr(1, 1) = RGB(255, 0, 0): Cr(2, 1) = RGB(0, 160, 0)
With ActiveSheet
.[a1].Resize(2, 1) = Ar
.[a1].Resize(2, 1).Font.Color = Cr
End With
End Sub
複製代碼
作者:
GBKEE
時間:
2015-7-13 05:27
回復
1#
justintoolbox
試試看
Option Explicit
Sub Ex()
Dim Ar(1 To 2, 1 To 1) As Variant, Cr(1 To 2, 1 To 1) As Variant
Dim i As Integer, ii As Integer
Ar(1, 1) = "A": Ar(2, 1) = "B"
Cr(1, 1) = RGB(255, 0, 0): Cr(2, 1) = RGB(0, 160, 0)
With ActiveSheet.[a1].Resize(UBound(Ar), UBound(Ar, 2))
.Value = Ar
For i = 1 To UBound(Ar)
For ii = 1 To UBound(Ar, 2)
.Cells(i, ii).Font.Color = Cr(i, ii)
Next
Next
End With
End Sub
複製代碼
作者:
justintoolbox
時間:
2015-7-13 06:32
回復 justintoolbox
試試看
GBKEE 發表於 2015-7-13 05:27
GBKEE!
非常感謝您!~你的方法真棒!
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)