VB Function to find last cell containing data in a column

backfromthebush

New Member
Joined
Jul 2, 2010
Messages
37
Hi,

Is there a function I can write using VB that will find the cell reference that contains the last data within that column?
e.g. cells A1:A10 all have data (lets say numbers for example), A11 will be empty. I need a function that will return the value A10 as the last cell in this column containing this data.
Can anyone help??!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Do you mean something like this?
Code:
Sub lastcellinA()
MsgBox Range("A:A")(Rows.Count).End(xlUp).Address(0, 0)
End Sub
 
Upvote 0
Yep, almost! Is there a way to create a custom function ? What I ultimately want to do is this:-
If cells A1:A5 had the numbers 1,2,3,4 & 5 in them respectively, I want a formula that will sum A1:A5 for me (=15). But if I was to add another value and put it in cell A6 (e.g. 6), then it automatically change the formula to A1:A6.
I guess the reason I'm doing this is that I am currently using a Sumproduct formula to do some calculations, but since this formula doesnt work when there are blank cells I have to change the cell range within the formula when I add a new line. I was hoping to automate this some how!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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