cell function to get table length... Help--

G

Guest

Guest
This it a part from an old macro I wrote a while back.
Now trying to get a cell function from it.

' Function to provide # of last line of table
as it is edited (row # needed for % is table)
'----------------------------------------
' ------ Clen (column length -finds last row) ------
Public Function CLen() As Integer
Range("A500").Select ' below max table length
Selection.End(xlUp).Select
CLen = ActiveCell.Row
' **?? number displayed is row last edited !!!
End Function
' -----------------------------

Now the function runs when row is deleted
does not run when row is inserted

How can I set this up so:
1) it runs when table changes size (can be by several ways
usually insert text copy, row insert, delete row)
2) Get correct line number (where function is placed at
end of col A)
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
On 2002-03-08 07:41, Anonymous wrote:
This it a part from an old macro I wrote a while back.
Now trying to get a cell function from it.

' Function to provide # of last line of table
as it is edited (row # needed for % is table)
'----------------------------------------
' ------ Clen (column length -finds last row) ------
Public Function CLen() As Integer
Range("A500").Select ' below max table length
Selection.End(xlUp).Select
CLen = ActiveCell.Row
' **?? number displayed is row last edited !!!
End Function
' -----------------------------

Now the function runs when row is deleted
does not run when row is inserted

How can I set this up so:
1) it runs when table changes size (can be by several ways
usually insert text copy, row insert, delete row)
2) Get correct line number (where function is placed at
end of col A)

You can change your function, to address question 1, to:

Public Function CLen() As Integer
Application.Volatile
CLen = Range("A65536").End(xlUp).Row
' **?? number displayed is row last edited !!!
End Function

I don't think you can build something in the function to address question 2 (but I'm bound to be wrong, someone else on the board will provide an answer and I'll learn something new. That's the beauty of this board :) ).

Regards,
 
Upvote 0
THANKS, its a start... Its been awhile since I have done much VB programming in Excel, but its as fun as I remember. haha
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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