I am running a code that pulls data from PI using conditional formula. When the values are pulled, it assigns the formula to entire column but only few of them have actual values:
The column has about 300,000 rows but I want to run the loop only when I have actual values (4 times instead of 300,000 in this case).
Are there any suggestions to do it avoiding the loop 300,000 times?
I have tried using the replace function by replacing all the spaces with blank and then count the number of non-blank cells using COUNTA
:
'Replacing all spaces in a column by blanks
Workseets("Sheet6").Range("D:D") = Replace(Worksheets("Sheet6").Range("D:D")," ","")
'counting non-blank cells
n = WorksheetFunction.CountA(Worksheets("Sheet6").Range("D:D"))
'running code only 4 times
for I = 1 to n.....
But I am getting type mismatch error for the replace function. I have not written anything inside for FOR Loop
yet. Currently just trying to use the REPLACE
function correctly
Dim n As Long
andDim I as Long
, 300,000 well exceeds the limit of integer data type. Also, please consider showing what you're doing inside the loop.Do While
loop instead ofFor
loop, with criteria to exit when the cell value is empty.Workseets("Sheet6").Range("D:D")
you'll define a proper Range variable that represents only the rows/data you want to process.