Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default dynamic ranges

I am looking for a means by which to select a range of cells
dynamically, by prompting excel to look for the last non-zero cell in a
column of data. My goal is to apply a name to a range of cells, but I
need to be sure that I capture all of the data in a column, so I am
hoping to write code that will allow me to specify the range of cells
dynamically, ending on the last cell in a column with a non-zero entry.
Any help is appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default dynamic ranges

Public Function LastCell(ByVal strColumn As String, Optional wks As
Worksheet) As Range
Dim rngLast As Range

If wks Is Nothing Then Set wks = ActiveSheet

Set rngLast = wks.Cells(Rows.Count, strColumn).End(xlUp)
Do While rngLast.Value = 0 And rngLast.Row 1
Set rngLast = rngLast.Offset(-1, 0)
Loop
Set LastCell = wks.Range(wks.Range(strColumn & "2"), rngLast)
End Function

Sub test() 'Run this code...
Dim rng As Range

On Error Resume Next
Set rng = LastCell("c")
If Not rng Is Nothing Then rng.Select
End Sub

--
HTH...

Jim Thomlinson


" wrote:

I am looking for a means by which to select a range of cells
dynamically, by prompting excel to look for the last non-zero cell in a
column of data. My goal is to apply a name to a range of cells, but I
need to be sure that I capture all of the data in a column, so I am
hoping to write code that will allow me to specify the range of cells
dynamically, ending on the last cell in a column with a non-zero entry.
Any help is appreciated.


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
Dynamic Ranges patrick Excel Discussion (Misc queries) 2 July 22nd 07 04:53 AM
Dynamic ranges Brad Charts and Charting in Excel 2 September 8th 06 08:39 PM
dynamic ranges Sam Excel Worksheet Functions 2 January 21st 05 07:46 PM
Dynamic Formulas with Dynamic Ranges Ralph Howarth Excel Worksheet Functions 5 January 21st 05 08:44 AM
Dynamic Ranges Q John[_78_] Excel Programming 6 December 9th 04 04:07 AM


All times are GMT +1. The time now is 01:25 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"