#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Copy Range

Hi,

I am trying to copy a range from one worksheet to another worksheet - in a
macro.
Is there anyway to save a range as a variable and then copy over the range.

Like

Dim Range1 as range

Range1= Range("A1:A100").value

Is there a good way to do this - right now I am using the copy paste command
in the macro - but there probably is a better way.

Thanks for your help


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Copy Range

One way:

Range("A1:A100").Copy Destination:=Sheets("Sheet2").Range("A1")

or, to copy just values:

Sheets("Sheet2").Range("A1:A100").Value = Range("A1:A100").Value

or perhaps:

With Sheets("Sheet1").Range("A1:A100")
Sheets("Sheet2").Range("A1").Resize( _
.Rows.Count, .Columns.Count).Value = .Value
End With

In article ,
Jeff wrote:

Hi,

I am trying to copy a range from one worksheet to another worksheet - in a
macro.
Is there anyway to save a range as a variable and then copy over the range.

Like

Dim Range1 as range

Range1= Range("A1:A100").value

Is there a good way to do this - right now I am using the copy paste command
in the macro - but there probably is a better way.

Thanks for your help

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Copy Range

Dim Rng1 as range
dim Rng2 as range

set rng1 = worksheets("sheet1").range("a1:A100")
set rng2 = worksheets("sheet2").range("d9") '<-- a single cell

rng1.copy _
destination:=rng2

==========
or

Dim Rng1 as range
dim Rng2 as range

set rng1 = worksheets("sheet1").range("a1:A100")
set rng2 = worksheets("sheet2").range("d9") '<-- a single cell

rng1.copy
rng2.pastespecial paste:=xlpaste values

=====
or
Dim Rng1 as range
dim Rng2 as range

set rng1 = worksheets("sheet1").range("a1:A100")
set rng2 = worksheets("sheet2").range("d9") '<-- a single cell

rng2.resize(rng1.rows.count,rng1.columns.count).va lue = rng2.value

===
The first copies everything--formulas, formats...
The last two just work with values.

Jeff wrote:

Hi,

I am trying to copy a range from one worksheet to another worksheet - in a
macro.
Is there anyway to save a range as a variable and then copy over the range.

Like

Dim Range1 as range

Range1= Range("A1:A100").value

Is there a good way to do this - right now I am using the copy paste command
in the macro - but there probably is a better way.

Thanks for your help


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Copy Range

Just a typo:

rng2.resize(rng1.rows.count,rng1.columns.count).va lue = rng2.value
should be
rng2.resize(rng1.rows.count,rng1.columns.count).va lue = rng1.value



Dave Peterson wrote:

Dim Rng1 as range
dim Rng2 as range

set rng1 = worksheets("sheet1").range("a1:A100")
set rng2 = worksheets("sheet2").range("d9") '<-- a single cell

rng1.copy _
destination:=rng2

==========
or

Dim Rng1 as range
dim Rng2 as range

set rng1 = worksheets("sheet1").range("a1:A100")
set rng2 = worksheets("sheet2").range("d9") '<-- a single cell

rng1.copy
rng2.pastespecial paste:=xlpaste values

=====
or
Dim Rng1 as range
dim Rng2 as range

set rng1 = worksheets("sheet1").range("a1:A100")
set rng2 = worksheets("sheet2").range("d9") '<-- a single cell

rng2.resize(rng1.rows.count,rng1.columns.count).va lue = rng2.value

===
The first copies everything--formulas, formats...
The last two just work with values.

Jeff wrote:

Hi,

I am trying to copy a range from one worksheet to another worksheet - in a
macro.
Is there anyway to save a range as a variable and then copy over the range.

Like

Dim Range1 as range

Range1= Range("A1:A100").value

Is there a good way to do this - right now I am using the copy paste command
in the macro - but there probably is a better way.

Thanks for your help


--

Dave Peterson


--

Dave Peterson
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 a specified name range Lori New Users to Excel 9 January 10th 07 01:13 PM
How do I copy formulas but using the same range each time I copy Laffin Excel Worksheet Functions 2 June 22nd 06 04:17 PM
help with range copy saziz Excel Discussion (Misc queries) 4 September 29th 05 06:34 PM
copy a range without the same value antoine Excel Discussion (Misc queries) 1 May 4th 05 12:18 PM
Copy a range GrantM Excel Worksheet Functions 1 December 21st 04 09:59 AM


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