VBA: Replacing space bars with blank spaces?
<p>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: </p>

<p><a href="https://i.stack.imgur.com/Qphbh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qphbh.png" alt="enter image description here"></a></p>

<p>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).</p>

<p>Are there any suggestions to do it avoiding the loop 300,000 times? </p>

<p>I have tried using the replace function by replacing all the spaces with blank and then count the number of non-blank cells using <code>COUNTA</code> :</p>

<pre><code>'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.....
</code></pre>

<p>But I am getting type mismatch error for the replace function. I have not written anything inside for <code>FOR Loop</code> yet. Currently just trying to use the <code>REPLACE</code> function correctly</p>