Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Defining Dynamic Range

I have a spreadsheet that may change in size daily. How can I refer to the
range in VBA? CurrentRegion doesn't work as there may be empty rows or
columns in the range I want to select.

Looking for something that would give me (A1:"bottom right cell")

Thanks for any ideas.

Jamie


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Defining Dynamic Range

Jamie,
ActiveSheet.UsedRange should give you what you need.
Jim Cone
San Francisco, USA

"Jamie" wrote in message
om
I have a spreadsheet that may change in size daily. How can I refer to the
range in VBA? CurrentRegion doesn't work as there may be empty rows or
columns in the range I want to select.
Looking for something that would give me (A1:"bottom right cell")
Thanks for any ideas.
Jamie


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Defining Dynamic Range

Thanks! That seems to do it.

Jamie

"Jim Cone" wrote in message
...
Jamie,
ActiveSheet.UsedRange should give you what you need.
Jim Cone
San Francisco, USA

"Jamie" wrote in message
om
I have a spreadsheet that may change in size daily. How can I refer to the
range in VBA? CurrentRegion doesn't work as there may be empty rows or
columns in the range I want to select.
Looking for something that would give me (A1:"bottom right cell")
Thanks for any ideas.
Jamie




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Defining Dynamic Range

Jamie,

If you want to pinpoint the area with data in it then try the following function.
The UsedRange can sometimes encompass blank rows/columns...
Jim Cone
San Francisco, USA
'-----------------------------------

Function BottomRightCorner(ByRef objSheet As Excel.Worksheet) As Excel.Range
' Jim Cone
'Returns a range object.
On Error GoTo NoCorner
Dim BottomRow As Long
Dim LastColumn As Long

' Optional line below could go in the calling sub,
' or a check for hidden cells could be done in the calling sub.
If objSheet.FilterMode Then objSheet.ShowAllData
BottomRow = objSheet.Cells.Find(what:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
LastColumn = objSheet.Cells.Find(what:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
Set BottomRightCorner = objSheet.Cells(BottomRow, LastColumn)
Exit Function

NoCorner:
Beep
Set BottomRightCorner = objSheet.Cells(1, 1)
End Function
'-----------------

'Call the function like this
Sub GetLastCellWithData()
Dim rngCell As Excel.Range
Set rngCell = BottomRightCorner(ActiveSheet)
MsgBox rngCell.Address 'for display purposes
Set rngCell = Nothing
End Sub
'-----------


"Jamie" wrote in message ...
Thanks! That seems to do it.
Jamie


"Jim Cone"
wrote in message
...
Jamie,
ActiveSheet.UsedRange should give you what you need.
Jim Cone
San Francisco, USA



"Jamie" wrote in message
om
I have a spreadsheet that may change in size daily. How can I refer to the
range in VBA? CurrentRegion doesn't work as there may be empty rows or
columns in the range I want to select.
Looking for something that would give me (A1:"bottom right cell")
Thanks for any ideas.
Jamie

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Defining Dynamic Range

Unfortunately, this doesn't always work when you have some merged
cells. I have seen it return column A when other columns have data.

Any ideas?

John

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
help defining dynamic range joecrabtree Charts and Charting in Excel 0 December 6th 06 03:33 PM
Defining Dynamic Ranges in Macro Prashant Garg Excel Programming 2 December 17th 04 01:47 AM
Defining a Range Kaval Excel Programming 2 September 5th 04 11:53 PM
Defining range Edgar[_3_] Excel Programming 2 February 17th 04 02:24 PM
Defining a range Matt Excel Programming 3 January 23rd 04 03:21 PM


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