Hi zach,
Looks like you're using VBA already. Here's a UDF and a Sub that both use Countif. The UDf goes in a cell as :
=Cols()
The code is code.
Option Explicit
Function Cols()
Dim x As Long
Dim Totl As Long
'Col A
Totl = Application.WorksheetFunction.CountIf(Range(Cells(5, 1).Address, Cells(65536, 1).Address), "<>")
'Col E
Totl = Totl + Application.WorksheetFunction.CountIf(Range(Cells(5, 5).Address, Cells(65536, 5).Address), "<>")
'remainder of Cols: Col # - 9 / Mod 4 = 0
For x = 9 To 253 Step 4
' add Col# countif to total
Totl = Totl + Application.WorksheetFunction.CountIf(Range(Cells(5, x).Address, Cells(65536, x).Address), "<>")
Next x
'return as function
Cols = Totl
End Function
Sub CountCols()
Dim x As Long
Dim Totl As Long
'Col A
Totl = Application.WorksheetFunction.CountIf(Range(Cells(5, 1).Address, Cells(65536, 1).Address), "<>")
'Col E
Totl = Totl + Application.WorksheetFunction.CountIf(Range(Cells(5, 5).Address, Cells(65536, 5).Address), "<>")
'remainder of Cols: Col # - 9 / Mod 4 = 0
For x = 9 To 253 Step 4
'add Col# countif to total
Totl = Totl + Application.WorksheetFunction.CountIf(Range(Cells(5, x).Address, Cells(65536, x).Address), "<>")
Next x
'return as sub
Range("A1") = Totl
End Sub
As for the last used Column - which row would you use to determine the Column? or perhaps add this:
'remainder of Cols: Col # - 9 / Mod 4 = 0
For x = 9 To 253 Step 4
'exit if Countif = 0
If Application.WorksheetFunction.CountIf(Range(Cells(5, x).Address, Cells(65536, x).Address), "<>") = 0 Then Exit For
'else add Col# countif to total
Totl = Totl + Application.WorksheetFunction.CountIf(Range(Cells(5, x).Address, Cells(65536, x).Address), "<>")
Next x
Cheers,
dr