Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default VBA for Last Cell in Formula Range

Using VBA
Trying to indentify the last cell on sheet that has a formula.

code fragment below

have tried
Set rge = Sh.UsedRange.SpecialCells(xlCellTypeFormulas,
xlCellTypeLastCell)
msgbox rge.Address

However I this returns the address of all formula cells

Any suggestions to get the address of the last cell with a formula ?

ie used range a1: j 100 , and last formula may be j 89

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default VBA for Last Cell in Formula Range

One way:

On Error Resume Next
With Sh.Cells.SpecialCells(xlCellTypeFormulas)
With .Areas(.Areas.Count)
Set rge = .Cells(.Count)
End With
End With
On Error GoTo 0
If Not rge Is Nothing Then MsgBox rge.Address



In article .com,
wrote:

Using VBA
Trying to indentify the last cell on sheet that has a formula.

code fragment below

have tried
Set rge = Sh.UsedRange.SpecialCells(xlCellTypeFormulas,
xlCellTypeLastCell)
msgbox rge.Address

However I this returns the address of all formula cells

Any suggestions to get the address of the last cell with a formula ?

ie used range a1: j 100 , and last formula may be j 89

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA for Last Cell in Formula Range

I think it depends on what you mean.

If I have a formula in A1:A100 and another in X1, what's the address of that
lastcell with a formula--is it A100 or X1?

But maybe...

Option Explicit
Sub testm()

Dim myRng As Range
Set myRng = Nothing
On Error Resume Next
Set myRng = Worksheets("Sheet1").Cells.SpecialCells(xlCellType Formulas)
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "hey, no formulas"
Else
With myRng
'last area of this multiarea range
With .Areas(.Areas.Count)
'last cell in this last area
MsgBox .Cells(.Cells.Count).Address
End With
End With
End If

End Sub

But I wouldn't trust this kind of thing--who knows how excel will order those
areas.

If I know what I want, I'd look through rows or columns trying to find that last
formula.

wrote:

Using VBA
Trying to indentify the last cell on sheet that has a formula.

code fragment below

have tried
Set rge = Sh.UsedRange.SpecialCells(xlCellTypeFormulas,
xlCellTypeLastCell)
msgbox rge.Address

However I this returns the address of all formula cells

Any suggestions to get the address of the last cell with a formula ?

ie used range a1: j 100 , and last formula may be j 89


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default VBA for Last Cell in Formula Range

just pick the last item from the range:

Sub last_formula()
Set rge = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las,
xlCellTypeLastCell)
f = Split(rge.Address, ",")
u = UBound(f)
MsgBox (f(u))
End Sub

--
Gary''s Student - gsnu200719


" wrote:

Using VBA
Trying to indentify the last cell on sheet that has a formula.

code fragment below

have tried
Set rge = Sh.UsedRange.SpecialCells(xlCellTypeFormulas,
xlCellTypeLastCell)
msgbox rge.Address

However I this returns the address of all formula cells

Any suggestions to get the address of the last cell with a formula ?

ie used range a1: j 100 , and last formula may be j 89


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
I want to use a cell Value as a named Range in a Formula tmjones Excel Worksheet Functions 3 August 24th 06 10:27 PM
Need a formula that finds the last used cell in a range samfw Excel Worksheet Functions 4 February 6th 06 03:30 PM
formula for named cell/range using cell values alex Excel Worksheet Functions 2 August 27th 05 06:44 PM
Using the text from a cell as a range name in a formula Fletch Excel Discussion (Misc queries) 3 June 13th 05 07:57 PM
How do I use text in a cell as a range name in a formula Kiwi Excel Discussion (Misc queries) 2 April 11th 05 04:17 AM


All times are GMT +1. The time now is 09:58 PM.

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

About Us

"It's about Microsoft Excel"