Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copy range of cells using VB

I need to copy a range of cells, but I don't know the cell I'm in.

For example, I may be cell "A6". I want to select and copy X number
of cells down. Every example shows 'Range("A6:A45").Select.' What I
need is something like 'Range(fromThisCell:toThisCell).Select' Can I
use the Offset command somehow to select a relitive number of cells?

I have two files open, and I want to copy a range of cells from one
sheet to the next. The problem is the range of data will always start
in row 6, but the columns will vary.

Any help with this will be greatly appreciated. If I did not present
my question clearly, please e-mail me and I will elaborate.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default copy range of cells using VB

You can use Resize

Activecell.Resize(6,1)

is 6 rows down from, including, the active cell.

Or Ramge("A6").Resize(6,1)

--

HTH

RP

"Stuart" wrote in message
om...
I need to copy a range of cells, but I don't know the cell I'm in.

For example, I may be cell "A6". I want to select and copy X number
of cells down. Every example shows 'Range("A6:A45").Select.' What I
need is something like 'Range(fromThisCell:toThisCell).Select' Can I
use the Offset command somehow to select a relitive number of cells?

I have two files open, and I want to copy a range of cells from one
sheet to the next. The problem is the range of data will always start
in row 6, but the columns will vary.

Any help with this will be greatly appreciated. If I did not present
my question clearly, please e-mail me and I will elaborate.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copy range of cells using VB

Bob,

Thanks for the quick responce.

The ActiveCell.Resize did not work; VB showed a 'compile error
=expected' and I could not figure out what I was missing.

But, using VB Help, I looked up the Resize function, and found that
"Selection.Resize(rangeToCopy, 1).Select" would in fact do exactly what
I wanted (and works!)

Again, thanks for pointing me in the right direction!

Stuart



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default copy range of cells using VB

Stuart,

I just tried to show you the technique, you have to set something to that
range, such as

Set myRange = ActiveCell.Resize(6,1)

which returns you a range object that you can work with.

I tend to avoid select like the plague if I can, it is slow and usually not
necessary.

--

HTH

RP

"Stuart Sigafoos" wrote in message
...
Bob,

Thanks for the quick responce.

The ActiveCell.Resize did not work; VB showed a 'compile error
=expected' and I could not figure out what I was missing.

But, using VB Help, I looked up the Resize function, and found that
"Selection.Resize(rangeToCopy, 1).Select" would in fact do exactly what
I wanted (and works!)

Again, thanks for pointing me in the right direction!

Stuart



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
Copy certain range of cells Wesleybrack Excel Discussion (Misc queries) 1 March 2nd 06 04:23 PM
How to use macros to copy a range of cells which can exclude some cells which I didn't want to be copied? excelnovice Excel Worksheet Functions 2 September 25th 05 12:38 AM
Copy Range of Cells in Same Row Moe Excel Discussion (Misc queries) 1 August 4th 05 06:47 PM
Copy cells into range of cells until cell change mdeanda Excel Worksheet Functions 1 April 22nd 05 08:41 PM
Copy a formula to a range of cells via VB6 using .Range(Cells(row,col), Cells(row,col)).Formula= statement Kevin Excel Programming 7 October 5th 04 08:11 PM


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