#1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 4
Default Range?

How do I specify a range from say "A1" down to the last non empty cell. I
know it should contain something like xlDown but I cant figure the whole
syntax.

thx.

And why nobody answered by last post?


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 5,302
Default Range?

Hi MAB

Try:
Dim LastCell As Range, Rng As Range

Set LastCell = Cells(Rows.Count, "A").End(xlUp)

Set Rng = Range(Range("A1"), LastCell)


---
Regards,
Norman



"MAB" wrote in message
...
How do I specify a range from say "A1" down to the last non empty cell. I
know it should contain something like xlDown but I cant figure the whole
syntax.

thx.

And why nobody answered by last post?




  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 4
Default Range?


"Norman Jones" wrote in message
...
Hi MAB

Try:
Dim LastCell As Range, Rng As Range

Set LastCell = Cells(Rows.Count, "A").End(xlUp)

Set Rng = Range(Range("A1"), LastCell)


---
Regards,
Norman


Thanks. This will work but has a problem. This will return the range from A1
to the cell below which all cells are empty. But what if there are further
empty cells above that cell? I want the range to not contain any empty cell
so it should
start from A1 and end when the first blank ( empty ) cell appears ( actually
one cell above the empty cell )


  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 5,302
Default Range?

Hi MAB,

Try:

Set rng = Range(Range("A1"), Range("A1").End(xlDown))

However for a more robust approach:

Sub Tester01()
Dim rng As Range
Dim StartCell As Range

Set StartCell = Range("A1") '<<== CHANGE TO SUIT

If Not IsEmpty(StartCell) Then
If Not IsEmpty(StartCell.Offset(1)) Then
Set rng = Range(StartCell, StartCell.End(xlDown))
End If
Else
Set rng = StartCell
End If

MsgBox rng.Address
End Sub


---
Regards,
Norman



"MAB" wrote in message
...

"Norman Jones" wrote in message
...
Hi MAB

Try:
Dim LastCell As Range, Rng As Range

Set LastCell = Cells(Rows.Count, "A").End(xlUp)

Set Rng = Range(Range("A1"), LastCell)


---
Regards,
Norman


Thanks. This will work but has a problem. This will return the range from
A1
to the cell below which all cells are empty. But what if there are further
empty cells above that cell? I want the range to not contain any empty
cell
so it should
start from A1 and end when the first blank ( empty ) cell appears (
actually
one cell above the empty cell )




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
How do I enter formula sum(range+range)*0.15 sumif(range=3) tkw Excel Discussion (Misc queries) 2 October 1st 09 09:17 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Translate range name passed as string to a custom function to range addresses! agarwaldvk[_25_] Excel Programming 3 September 7th 04 12:47 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


All times are GMT +1. The time now is 05:55 AM.

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"