Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Setting range to last occupied cell

I want to copy a range going from a known cell, say D4, to the last occupied
cell in column G.

I have been given the following as a suggestion to find the last occupied
row in a column, but how do I use that in a range statement in vba?
lastrow = Cells(Cells.Rows.Count, "G").End(xlUp).Row

Also will this only find the last contiguously occupied row (if that's the
right word). ie will it ignore an empty row before the row containing column
totals which I don't want to include in the range.

Is there a better solution?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Setting range to last occupied cell



lastrow = Cells(Cells.Rows.Count, "G").End(xlUp).Row

equal to:

lastrow = Cells(65536, "G").End(xlUp).Row

in vba:
= Range("G65536").End(xlUp).Row

as it start counting from G65536 till up and reach an End, just like you
press "End" then "Up Arrow" key.

for other range, just change the colume letter for the range.



"Ken G" wrote:

I want to copy a range going from a known cell, say D4, to the last occupied
cell in column G.

I have been given the following as a suggestion to find the last occupied
row in a column, but how do I use that in a range statement in vba?
lastrow = Cells(Cells.Rows.Count, "G").End(xlUp).Row

Also will this only find the last contiguously occupied row (if that's the
right word). ie will it ignore an empty row before the row containing column
totals which I don't want to include in the range.

Is there a better solution?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Setting range to last occupied cell

Try

Dim rngTemp As Range
Set rngTemp = Range("G1", Range("G1").End(xlDown))
MsgBox rngTemp.Address


--
Jacob


"Ken G" wrote:

I want to copy a range going from a known cell, say D4, to the last occupied
cell in column G.

I have been given the following as a suggestion to find the last occupied
row in a column, but how do I use that in a range statement in vba?
lastrow = Cells(Cells.Rows.Count, "G").End(xlUp).Row

Also will this only find the last contiguously occupied row (if that's the
right word). ie will it ignore an empty row before the row containing column
totals which I don't want to include in the range.

Is there a better solution?

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
newbie - how to paste into an occupied cell Vic Baron New Users to Excel 5 June 5th 08 07:52 PM
Selecting occupied cell over empty ones Rich Excel Discussion (Misc queries) 0 March 28th 07 02:53 AM
Selecting occupied cell over empty ones Teethless mama Excel Discussion (Misc queries) 1 March 28th 07 02:13 AM
subtract from numeric cell when alpha cell is occupied Keith Excel Worksheet Functions 0 March 28th 07 01:04 AM
Selecting occupied cell over empty ones Rich Excel Discussion (Misc queries) 0 March 28th 07 12:05 AM


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