WorksheetFunction. Функция индекса работает не так, как должна - PullRequest
0 голосов
/ 09 мая 2019

Я вытащил расчетный отчет о доходах, основанный на списке продуктов и годах запуска в выпадающем списке.Из отчета видно, что функция Index не циклически перебирает (циклично) список, вместо этого отображается только 1 выбор.

ошибка времени выполнения '424', требуется объект.

Sub Bridge()
Dim cntP, cntY, cntProduct, cntYear, cntRow As Variant

Const Output_Height As Integer = 4
cntRow = 1


Application.ScreenUpdating = False


'Clear the Connect rate sheet
Sheet41.range("A11:U300").Clear

cntP = Application.WorksheetFunction.CountA(range("Product_List")) 'Count the number of product
cntY = Application.WorksheetFunction.CountA(range("Product_Years")) 'Count the number of years

'For loop for each of the Products
For cntProduct = 1 To cntP
        Prod_Name_Selection = Application.WorksheetFunction.Index([Product_Years], cntProduct)


    'For loop for each of the years within the loop of each product
    For cntYear = 1 To cntY
        Year_Selection = Application.WorksheetFunction.Index([Product_Years], cntYear)

         'Copy the Cartidge Count output to the Connect rate sheet
        Sheet13.range("Bridge_table").Copy

        Sheet41.range("C6").Offset(Output_Height * (cntRow - 1) + 5, 0).PasteSpecial Paste:=xlPasteColumnWidths
        Sheet41.range("C6").Offset(Output_Height * (cntRow - 1) + 5, 0).PasteSpecial Paste:=xlPasteFormats
        Sheet41.range("C6").Offset(Output_Height * (cntRow - 1) + 5, 0).PasteSpecial Paste:=xlPasteValues

        cntRow = cntRow + 3

    Next
Next

Application.ScreenUpdating = True

End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...