Picking up the last non-empty cell in a given range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have given a range (say a1.a100 which contain IF function in every cell) to
my users. They are to enter value into the cell everyday continuously.

Can anyone help me with VBA codes for me to pick up the last entered value
(say A42, A43 onwards are still empty) on anyday, to be linked to another
workbook?

I used the SpecialCells(xlCellTypeLastCell) feature, it doesn't work. It
always return A100, possibly because A100 contains an IF statement.

Thanks.
 
something like this :- ??

r = 1
While ActiveSheet.Cells(r, 1).Value <> 0
r = r + 1
Wend
ActiveSheet.Cells(r, 1).Select
 
zhj23 said:
I have given a range (say a1.a100 which contain IF function in every cell) to
my users. They are to enter value into the cell everyday continuously.

Can anyone help me with VBA codes for me to pick up the last entered value
(say A42, A43 onwards are still empty) on anyday, to be linked to another
workbook?

I used the SpecialCells(xlCellTypeLastCell) feature, it doesn't work. It
always return A100, possibly because A100 contains an IF statement.

Thanks.

Put this in a macro and it should find the next empty cell in Col A
Range("A65536").End(xlUp).Offset(1, 0).Select
 
I think you should reconsider what you are doing, but with the
information provided you appear to want the cell below the
last constant in Column A. The following will do that.

Sub afterlastconstant()
Dim rng As Range, L As Long, M As Long
Set rng = Columns("A:A").SpecialCells(xlCellTypeConstants, 23)
L = rng.Areas.Count
M = rng(L).Count
rng.Areas(L).Item(M).Offset(1, 0).Select
End Sub

The above solution has no loops, so should run very fast.
there is problem with Special cells with over 8,192 non-contiguous cells
in other words more than 4096 separate areas of contiguous constants,
which you are much more likely to encounter if you have alternate rows of data..

Another solution offered is dependent on there always being 65536 rows
since that number has changed in the past and may change again it should
not be a constant cells.rows.count should be used instead of 65536
http://www.mvps.org/dmcritchie/excel/toolbars.htm#macros
In any case it is the wrong solution for this thread, since cells with formulas
are definitely not empty and cell A100 has a formula.
 
Hi! All:

Thanks for all the suggestions. I am working on it now.

David: If every cell in my range has an IF function, can it still be
considered as
"xlCellTypeConstants"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top