通過 VBA 中的輸入創建數組 (Creath an array by input in VBA)


問題描述

通過 VBA 中的輸入創建數組 (Creath an array by input in VBA)

我想創建一個數組來存儲公司不同部門的名稱。首先,我讓用戶輸入部門的總數,然後創建一個數組,讓用戶輸入部門的名稱。但是編譯器說數組的索引超出範圍。

Dim myarray As Variant
myarray = Array

deptnum = InputBox("Please enter the total amount of departments.")

For k = 0 To deptnum
x = InputBox("Please enter the name of department:"
x = myarray(k)
Next
</code></pre>


參考解法

方法 1:

If you still use the array, you can use the redim array, then use array(index) to assign the name you have entered.

Sub Test()
    Dim departments() As String
    Dim x As String

    deptnum = InputBox("Please enter the total amount of departments.")
    If Not (IsNumeric(deptnum)) Then Exit Sub
    ReDim departments(deptnum ‑ 1)

    For k = 0 To deptnum ‑ 1
        x = InputBox("Please enter the name of department:")
        departments(k) = x
    Next
End Sub

(by Chih‑Yu ChangDang D. Khanh)

參考文件

  1. Creath an array by input in VBA (CC BY‑SA 2.5/3.0/4.0)

#store #input #excel #vba #arrays






相關問題

Sencha touch 2:通過代理在商店檢索信息 (Sencha touch 2: retrieve infos by proxy in store)

Đại diện cửa hàng ExtJS Costum (ExtJS Costum store representation)

Cửa hàng Sencha Touch 2 đạt kỷ lục (Sencha Touch 2 store get record)

更換和存放 (Replacing and Storing)

如何重命名Window Store App的.exe(可執行文件)文件? (How to rename .exe (executable) file of Window Store App?)

Socket.io 和 Extjs:為 Store 檢索數據 (Socket.io and Extjs: Retrieving data for Store)

獲取組件中的輸入值反應本機 (Get a value of input in a component react native)

為小組存儲生產密碼的最佳實踐 (Best practices for storing production passwords for small groups)

有人可以解釋一下 iphone 證書的東西,步驟是什麼樣的嗎? (Can someone explain me the iphone certificate stuff, how the steps look like?)

用戶退出應用程序時在 MapKit 中存儲註釋 (Store annotations in MapKit when user quit application)

使用 Injector angular 7 將 Store 注入子類 (Injecting Store to sub classes using Injector angular 7)

通過 VBA 中的輸入創建數組 (Creath an array by input in VBA)







留言討論