I'm trying to count all the cells in a column that have values above the active cell, excluding the first cell and the cell immediately above the active cell.
For example if I have a column
1
5
4
N/A
4
current cell
I want the current cell to equal 2. (Counting the 5 and 4, not the N/A, not the cell above current cell, and not the first cell)
The number of cells in the column will vary.
I want this for 260 consecutive columns.
I have the following code from this answer but the number of cells in the column is 6 rather than flexible:
Sub counter()
Dim firstCol as Integer
dim lastCol as Integer
firstCol = 1 'You can change this value depending on your first column
' for example you might use ActiveCell.Column
lastCol = firstCol + 260
Dim col As Integer
Dim lastrow As Integer
lastRow = 6 ' Make this the actual last row of the data to include
Dim cellcount As Integer
for col = firstCol to lastCol
cellcount = 0
For Each cell In ActiveSheet.Range(Cells(2, col), Cells(lastrow, col))
If IsError(cell) Then GoTo skipcell
If cell.Value > 0 And IsNumeric(cell) Then cellcount = cellcount + 1
skipcell:
Next cell
ActiveSheet.Cells(lastRow + 2, col) = cellcount
Next col
End Sub
lastRow = 6so that the6is whatever your last row is.