Путешествие по выбору при использовании CountA - PullRequest
0 голосов
/ 17 июня 2019

Я пытаюсь перебрать свой рабочий лист и посчитать, есть ли в них несколько разных диапазонов.В настоящее время я не могу понять, как изменить диапазоны в функции CountA без использования .Select, которую не любит использовать большая часть сообщества VBA, поэтому я стараюсь держаться от этого подальше.

Dim BoxCounter As Integer
Dim TestCounter As Integer
Dim I As Integer
Dim TestExists As Integer
i=0
With ThisWorkbook.Worksheets("Configuration Sheets")
    While (BoxCounter <= 571) 'goes to the last row used for this specific sheet. 

            If (Application.WorksheetFunction.CountA(("F" & (4 + i * 25) & ":F" & (15 + i * 25))) >= 1) Then
            TestExists = TestExists + 1
            i = i + 1
            BoxCounter = BoxCounter + 30 'adds on so that I can loop through all of the rows, 30 is the size of the specific information spaces
        Wend
    End With

1 Ответ

1 голос
/ 17 июня 2019

При использовании Application.WorksheetFunction.CountA("range"), "range" будет ссылаться на активный лист, если вы не используете формат "worksheet!range". Таким образом, вместо использования строкового диапазона, лучше использовать объект диапазона из нужного листа:

Dim BoxCounter As Integer
Dim TestCounter As Integer
Dim I As Integer
Dim TestExists As Integer
i=0
With ThisWorkbook.Worksheets("Configuration Sheets")
    While (BoxCounter <= 571) 'goes to the last row used for this specific sheet. 

            If (Application.WorksheetFunction.CountA(.Range("F" & (4 + i * 25) & ":F" & (15 + i * 25))) >= 1) Then
            TestExists = TestExists + 1
            i = i + 1
            BoxCounter = BoxCounter + 30 'adds on so that I can loop through all of the rows, 30 is the size of the specific information spaces
        Wend
    End With
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...