1

5 つの整数を宣言しました

    Public Hol_1 as integer
    Public Hol_2 as integer
    Public Hol_3 as integer
    Public Hol_4 as integer
    Public Hol_5 as integer

3 つのクライアントがあり、Hol_1 から Hol_3 を使用するとします。これは次のことも意味します: iClients = 3 最初に、シート ("Holidays") を調べて、3 人のクライアントのそれぞれの休日の日数を確認する必要があります。

    Sub CountHolidays()

    Dim i as integer
    Dim iclients as integer
    iclients = 3
    For i=1 to iclients 
        Hol_i = WorksheetFunction.CountA(ActiveWorkbook.Sheets("Holidays").Range(Cells(2, 3 + i), Cells(50, 3 + i))) 
       'The worksheetfunction calculates the amount of Holiday-dates I have for each of my three clients
    Next i
    End sub

Variable is not defined: Hol_i is not defined というコンパイル エラーが発生します。"Hol_" & i などを試しましたが、これを修正できませんでした。誰かアイデアがありますか?THX

4

1 に答える 1

4

変数名を連結することはできません。 はwhenHol_iとは完全に別の変数です。Hol_1i=1

これを行うには配列が必要です。

Dim Hol(5) as Integer

For i=1 to iclients 
  Hol(i) = WorksheetFunction.CountA(ActiveWorkbook.Sheets("Holidays").Range(Cells(2, 3 + i), Cells(50, 3 + i)))
Next i
于 2013-01-17T15:06:21.633 に答える