Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Last numeric cell

Trying to use a macro to find the last NUMERIC cell after a range has been
sorted.
ie:

using the following in a macro----
Range(Range("l25"), Range("l25").End(xlDown)).Select

column l:

1
5
8
6
1 I want to find this cell
blank cell
blank cell
blank
and so on

TOS
TOS
TOS
Tos The above macro finds this cell.

Any help appreciated.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Last numeric cell


Your data as presented is not sorted...
"1" appears in two non-adjacent cells and the blank cells are not at the bottom.
The following works, but only in a single sorted column...

Dim rng As Range
Set rng = Selection.SpecialCells(xlCellTypeConstants, xlNumbers)
Set rng = rng(rng.Count)
MsgBox rng.Address

Another way would be to loop from the bottom up looking for any number.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"shawnews"
wrote in message
Trying to use a macro to find the last NUMERIC cell after a range has been
sorted.
ie:
using the following in a macro----
Range(Range("l25"), Range("l25").End(xlDown)).Select

column l:

1
5
8
6
1 I want to find this cell
blank cell
blank cell
blank
and so on

TOS
TOS
TOS
Tos The above macro finds this cell.

Any help appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Last numeric cell

I'm confused about what you're selecting, but if your numbers are values (not
formulas), you can use something like:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim LastNumericCell As Range
Dim JustNumberConstants As Range

Set wks = ActiveSheet

Set JustNumberConstants = Nothing
On Error Resume Next
Set JustNumberConstants _
= wks.Range("a:a").Cells.SpecialCells(xlCellTypeCons tants, xlNumbers)
On Error GoTo 0

If JustNumberConstants Is Nothing Then
MsgBox "No number constants"
Else
With JustNumberConstants
With .Areas(.Areas.Count)
Set LastNumericCell = .Cells(.Cells.Count)
End With
End With

MsgBox LastNumericCell.Address & vbLf & LastNumericCell.Value
End If
End Sub

If your numbers are all the results of formulas, you could use:

Set JustNumberConstants _
= wks.Range("a:a").Cells.SpecialCells(xlCellTypeForm ulas, xlNumbers)

It gets a bit uglier if you have a mixture.



shawnews wrote:

Trying to use a macro to find the last NUMERIC cell after a range has been
sorted.
ie:

using the following in a macro----
Range(Range("l25"), Range("l25").End(xlDown)).Select

column l:

1
5
8
6
1 I want to find this cell
blank cell
blank cell
blank
and so on

TOS
TOS
TOS
Tos The above macro finds this cell.

Any help appreciated.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TO DELETE ONLY NUMERIC VALUES IN A CHARACTER AND NUMERIC CELL IN ramesh k. goyal - abohar[_2_] Excel Discussion (Misc queries) 1 October 28th 09 06:50 AM
How do I copy numeric section of cell from alpha-numeric cell ACCAguy Excel Worksheet Functions 8 September 8th 08 12:46 PM
How to populate a cell with numeric value based on textselected from pull down in adjacent cell? Garth Rodericks Excel Worksheet Functions 1 September 5th 08 02:03 AM
only extract numeric value from alpha numeric cell Fam via OfficeKB.com Excel Discussion (Misc queries) 5 April 26th 06 06:49 PM
Numeric in Text to convert back to the form of Numeric for VLookup Purposes achilles Excel Discussion (Misc queries) 4 February 6th 06 07:05 AM


All times are GMT +1. The time now is 06:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"