Reputation: 49
So far I've managed to create a search feature that scans a column and collect rows in an Array. Then I print the array in another sheet to form a table. I do this with a number of criteria which means that I get different arrays with different sizes.
For my problem. I want to do a calculation for each Row. ActiveCell.FormulaR1C1 =" = TRUNC ((RC [-5], RC [-1]) / 7) "
. How do I make a loop that adapts to how many lines there are. There are also gaps in some places.
Here is an example for how one array is printed:
For i = 1 To nS - 1
Sheets("DataSheet").Select
Union(Sheets("raw_list").Cells(arrStart(i), NameCol), Sheets("raw_list").Cells(arrStart(i), PhaseCol), Sheets("raw_list").Cells(arrStart(i), ToStartCol), Sheets("raw_list").Cells(arrStart(i), ToDefineCol), Sheets("raw_list").Cells(arrStart(i), ToMeasureCol), Sheets("raw_list").Cells(arrStart(i), ToAnalyseCol), Sheets("raw_list").Cells(arrStart(i), ToImproveDevCol), Sheets("raw_list").Cells(arrStart(i), ToImproveIndCol), Sheets("raw_list").Cells(arrStart(i), ToControlCol), Sheets("raw_list").Cells(arrStart(i), ToClosedCol)).Copy
Cells(r, 1).Select
ActiveSheet.Paste
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
r = r + 1
Next
Thankful for any help!
Edit: Added a picture to show how it looks.
Upvotes: 1
Views: 652
Reputation: 8942
If there are gaps, what we use at work is a simple but not-so-elegant solution which is to add markers of some sort in adjacent columns. For example, we'd add "END" or something like that in the cell of the same row but either col + 1 or col - 1 to the column you are comparing to.
Another solution would be to look if the next element is also a blank, but that will work only if you have single gaps.
Finally, the last solution I see is that when you are on a blank, use xlDown and if you are at the last cell 65535 in 2003 and near a million in 2007 if my memory serves me right, then you are finished.
Upvotes: 2