VBA CountA entire column using column index?

gifariz

Board Regular
Joined
May 2, 2021
Messages
128
Office Version
  1. 365
Platform
  1. Windows
In VBA, is possible to count non-empty cells in a column given column index?
Something like this but using 6 as input instead of F
VBA Code:
n = WorksheetFunction.CountA(Range("F:F"))

What I can think of is to make very long array of possible alphabets, but it doesn't look good.
VBA Code:
ColNames = Array(A,B,C,D,E,F,G,H,I,J) 'and so on until ZZ
Col_ID = 6 'this is the input
col = ColNames(Col_ID - 1)
n =  WorksheetFunction.CountA(Range(col & ":" & col))

And using R1C1 style in spreadsheet is also not preferable for me. Its okay if only in VBA, but not if changing display in excel into R1C1 style.

TIA
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
One way.

VBA Code:
    Col_ID = 6
    With ActiveSheet
        n = Application.WorksheetFunction.CountA(.Range(.Cells(1, Col_ID), .Cells(.Rows.Count, Col_ID).End(xlUp)))
    End With
 
Upvote 0
One way.

VBA Code:
    Col_ID = 6
    With ActiveSheet
        n = Application.WorksheetFunction.CountA(.Range(.Cells(1, Col_ID), .Cells(.Rows.Count, Col_ID).End(xlUp)))
    End With
Thank you!
 
Upvote 0
Try:
VBA Code:
n = WorksheetFunction.CountA(Columns(6))
 
Upvote 0
Solution
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top