iT邦幫忙

0

Excel VBA 宣告問題

  • 分享至 

  • xImage

https://ithelp.ithome.com.tw/upload/images/20210907/20131103ZOF24eOB9p.jpg

請問以上有辦法縮減內容嗎,知道迴圈 1 to 5,但是宣告y部分不知道能不能放入迴圈變數

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
rogeryao
iT邦超人 8 級 ‧ 2021-09-07 08:21:13
最佳解答

請參閱 : Excel VBA 程式設計教學:陣列(Array)
請參閱 : Excel VBA 儲存格顏色移動
關鍵字 :
MyArray(ColorCount) = Cells(Z, M).Interior.Color
Cells(Z, 5 - K + 1).Interior.Color = MyArray(K)

非常感謝,讓我對陣列有更好的使用方式

0
blanksoul12
iT邦研究生 5 級 ‧ 2021-09-07 13:15:24
Sub test()

Set oFields = CreateObject("Scripting.Dictionary")
With oFields
    For y = 1 To 5
        '.Add "y" & y, Cells(1, y).Text '數值
        .Add "y" & y, Cells(1, y) '該 cells 內之所有東西
    Next
End With

t = oFields.Keys
k = oFields.Items

End Sub

我要發表回答

立即登入回答