CountA(Range("A:A")) + 1 ?

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I have this code part of a form to enter first and last name and the form has 3 buttons: enter, clear, and search. the code below is when user click on "enter". the code makes sure the data will be entered in next empty like. The part i do not understand is this

x = WorksheetFunction.CountA(Range("A:A")) + 1

Can you please explain to me what this code suppose to do?

Thanks you so much.
+++

Private Sub enter_Click()
Dim x As Long
x = WorksheetFunction.CountA(Range("A:A")) + 1
Cells(x, 1) = first.Value
Cells(x, 2) = last.Value
first.Value = ""
last.Value = ""
Me.first.SetFocus
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
This function counts non empty cells in a column A, then adds 1 to the result. Which gives the address of the next row where new data from your form should be put.

Oh. Btw. CountA can sometime give false results which can overwrite a data or skip one row.
Imo this is better:

Code:
with activesheet
        x = .Range("A" & Rows.Count).end(xlUp).Row + 1
end with
 
Last edited:
Upvote 0
It's meant to count the no of values in column A and from that work out the last row with data, then 1 is added to get the first empty row.

It's one of various techniques to do this, i.e. find the next empty row.
 
Upvote 0
This function counts non empty cells in a column A, then adds 1 to the result. Which gives the address of the next row where new data from your form should be put.

Oh. Btw. CountA can sometime give false results which can overwrite a data or skip one row.
Imo this is better:

Code:
with activesheet
        x = .Range("A" & Rows.Count).end(xlUp).Row + 1
end with
Solution of CountA give false result which can overwrite a data ,just you change RC (row,column) reference (not use RC) in excel.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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