簡體   English   中英

Excel VBA:自定義功能不起作用

[英]Excel VBA: Custom Function not behaving

我正在開發自定義功能,以幫助從數據集中收集更詳細的信息。 我擅長識別該函數的存在,它可以讓我輸入參數,但它給了我#VALUE! 錯誤。

我懷疑這可能與某些數組以及我要如何收集要顯示的數據有關。

我有2個表,主要數據表和一個調用表,其中包含我要收集的額外數據。

我正在根據開始時間和持續時間查看每個項目占用多少個“廣告位”。 我嘗試使用“直到”循環將項目所占用的“插槽”填充到數組中,然后在函數的輸出單元格中顯示該列表。 隨意忽略我的評論。

 Function SlotsOccupied(Duration, StartTime, Day)


    Dim SlotsUsed() As String
    ReDim SlotsUsed(0 To Duration)  'sets SlotsUsed array size
    Dim StartT(0 To 1)    'sets Array StartT
    Dim StarTarr As Variant
    Dim DurCount as Integer
    Dim SlotCount as Integer
    Dim StartTCount as Integer


                                      'Sets Counts and starting variables
    DurCount = 0
    SlotCount = 0
    StartTCount = StartTime


    StartT(0) = Day                 'sets StartT array values
    StartT(1) = StartTime


    Do Until DurCount = Duration

        StartTarr = Join(StartT, ",")

        Slot = Application.WorksheetFunction.VLookup(StarTarr, Slots.Range("a2:b56"), 2, False)

        SlotsUsed(SlotCount) = Slot

        DurCount = DurCount + 1
        StartTCount = StarTCount + 1
        SlotCount = SlotCount + 1

    Loop

    SlotsOccupied = Join(SlotsUsed, ",")

任何幫助將不勝感激,我已經很長時間沒有做任何編碼了,我感到腦子里生銹了。

提前致謝。

您永遠不會使變量durcount,slotcount或starttcount變暗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM