PC Review


Reply
Thread Tools Rate Thread

Copy & Paste Dynamic Named Range

 
 
EE
Guest
Posts: n/a
 
      18th Jan 2008
Hi all

I have a database of about 10 rows and 5000 columns (Starting from
A5).

I created a cell (D2) in the file where I enter a number (say 100) and
gave it a name (NumOfRows).

I have created Dynamic Named RAnges (for CHARTING) in such a way that
from a reference cell (Say G5), it will look for the number in
"NumOfRows" and select as many rows in that column for the graph.

Now I have a need to PASTE the same data in another sheet. I assume
that for this I need to select an exact sized range to paste the named
range (correct me if I am wrong)

I am using the following code but it does not work. Where am I going
wrong?

Thanks in advance for your help.

Best
Prasad
**********************
Sub Test()
Worksheets("Data").Select
Range("J4").Select
ActiveCell.FormulaR1C1 = "X Range"
Range("J4").Select
'NumOfRows is my NAmed RAnges for the cell called
ActiveCell.Offset(1, 0).Resize(Range("NumOfRows").Value, 0).Select
Selection.Value = Worksheets("SampleData1").Range("XRange").Value
End Sub
*********************************
 
Reply With Quote
 
 
 
 
EE
Guest
Posts: n/a
 
      18th Jan 2008
On Jan 18, 1:18*pm, EE <pras1...@gmail.com> wrote:
> Hi all
>
> I have a database of about 10 rows and 5000 columns (Starting from
> A5).
>
> I created a cell (D2) in the file where I enter a number (say 100) and
> gave it a name (NumOfRows).
>
> I have created Dynamic Named RAnges (for CHARTING) in such a way that
> from a reference cell (Say G5), it will look for the number in
> "NumOfRows" and select as many rows in that column for the graph.
>
> Now I have a need to PASTE the same data in another sheet. I assume
> that for this I need to select an exact sized range to paste the named
> range (correct me if I am wrong)
>
> I am using the following code but it does not work. Where am I going
> wrong?
>
> Thanks in advance for your help.
>
> Best
> Prasad
> **********************
> Sub Test()
> Worksheets("Data").Select
> Range("J4").Select
> ActiveCell.FormulaR1C1 = "X Range"
> Range("J4").Select
> 'NumOfRows is my NAmed RAnges for the cell called
> ActiveCell.Offset(1, 0).Resize(Range("NumOfRows").Value, 0).Select
> Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> End Sub
> *********************************


Hi folks

Have addressed the problem.

The revised code is this:

***************
Sub Test()
Dim Rng As Variant
Rng = Worksheets("SampleDAta1").Range("R2")
Worksheets("Data").Select
Range("J4").Select
ActiveCell.FormulaR1C1 = "X Range"
Range("J4").Offset(Rng, 0).Select
Range("J5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Value = Worksheets("SampleData1").Range("XRange").Value
End Sub
************************************

Any advice to simplify this is appreciated.

Best
Prasad
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      18th Jan 2008
I didn't try this, but see if it does what you want.

"EE" wrote:

> On Jan 18, 1:18 pm, EE <pras1...@gmail.com> wrote:
> > Hi all
> >
> > I have a database of about 10 rows and 5000 columns (Starting from
> > A5).
> >
> > I created a cell (D2) in the file where I enter a number (say 100) and
> > gave it a name (NumOfRows).
> >
> > I have created Dynamic Named RAnges (for CHARTING) in such a way that
> > from a reference cell (Say G5), it will look for the number in
> > "NumOfRows" and select as many rows in that column for the graph.
> >
> > Now I have a need to PASTE the same data in another sheet. I assume
> > that for this I need to select an exact sized range to paste the named
> > range (correct me if I am wrong)
> >
> > I am using the following code but it does not work. Where am I going
> > wrong?
> >
> > Thanks in advance for your help.
> >
> > Best
> > Prasad
> > **********************
> > Sub Test()
> > Worksheets("Data").Select
> > Range("J4").Select
> > ActiveCell.FormulaR1C1 = "X Range"
> > Range("J4").Select
> > 'NumOfRows is my NAmed RAnges for the cell called
> > ActiveCell.Offset(1, 0).Resize(Range("NumOfRows").Value, 0).Select
> > Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> > End Sub
> > *********************************

>
> Hi folks
>
> Have addressed the problem.
>
> The revised code is this:
>
> ***************
> Sub Test()
> Dim Rng As Variant
> Rng = Worksheets("SampleDAta1").Range("R2")
> Worksheets("Data").Select
> Range("J4").Select
> ActiveCell.FormulaR1C1 = "X Range"
> Range("J4").Offset(Rng, 0).Select
> Range("J5").Select
> Range(Selection, Selection.End(xlDown)).Select
> Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> End Sub
> ************************************
>
> Any advice to simplify this is appreciated.
>
> Best
> Prasad
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      18th Jan 2008
It helps to include the code.

Sub Test()
Dim Rng As Variant
Rng = Worksheets("SampleDAta1").Range("R2")
Worksheets("Data").Range("J4") = "X Range"
Range("J5:J" & End(xlDown).Row).Value = _
Worksheets("SampleData1").Range("XRange").Value
End Sub

"EE" wrote:

> On Jan 18, 1:18 pm, EE <pras1...@gmail.com> wrote:
> > Hi all
> >
> > I have a database of about 10 rows and 5000 columns (Starting from
> > A5).
> >
> > I created a cell (D2) in the file where I enter a number (say 100) and
> > gave it a name (NumOfRows).
> >
> > I have created Dynamic Named RAnges (for CHARTING) in such a way that
> > from a reference cell (Say G5), it will look for the number in
> > "NumOfRows" and select as many rows in that column for the graph.
> >
> > Now I have a need to PASTE the same data in another sheet. I assume
> > that for this I need to select an exact sized range to paste the named
> > range (correct me if I am wrong)
> >
> > I am using the following code but it does not work. Where am I going
> > wrong?
> >
> > Thanks in advance for your help.
> >
> > Best
> > Prasad
> > **********************
> > Sub Test()
> > Worksheets("Data").Select
> > Range("J4").Select
> > ActiveCell.FormulaR1C1 = "X Range"
> > Range("J4").Select
> > 'NumOfRows is my NAmed RAnges for the cell called
> > ActiveCell.Offset(1, 0).Resize(Range("NumOfRows").Value, 0).Select
> > Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> > End Sub
> > *********************************

>
> Hi folks
>
> Have addressed the problem.
>
> The revised code is this:
>
> ***************
> Sub Test()
> Dim Rng As Variant
> Rng = Worksheets("SampleDAta1").Range("R2")
> Worksheets("Data").Select
> Range("J4").Select
> ActiveCell.FormulaR1C1 = "X Range"
> Range("J4").Offset(Rng, 0).Select
> Range("J5").Select
> Range(Selection, Selection.End(xlDown)).Select
> Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> End Sub
> ************************************
>
> Any advice to simplify this is appreciated.
>
> Best
> Prasad
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      19th Jan 2008
Now I have a need to PASTE the same data in another sheet. I assume
that for this I need to select an exact sized range to paste the named
range (correct me if I am wrong)

If you copy the entire row then you must paste into a range beginning in
column A and far enough from the bottom of the sheet for all the rows to fit.
However, if your range copied is less than an entire row and less than an
entire column, then you just have to make sure that there is enough space
available, it does not have to be exact, just big enough.

If you wanted to copy rows 2 - 6 then from sheet1 to sheet2 then

Worksheets("Sheet1").Rows(2:6).EntireRow.Copy _
Worksheets("Sheet2").Range("A2")

This would all be one line in VBA and would copy the five rows from sheet1
to the same location on sheet 2. It has to be anchored in Column A.

Worksheets(1).Range("A2:F6").Copy Worksheets(2).Range("C7")

This line would copy a 6 x 6 range of cells from sheet1 and paste it into
sheet2 with the top left corner anchored in Cell C7, or to Range("C7:H13")

When you copy and paste, you need to know where your data is going because
the paste action will overwrite existing data.


"EE" wrote:

> Hi all
>
> I have a database of about 10 rows and 5000 columns (Starting from
> A5).
>
> I created a cell (D2) in the file where I enter a number (say 100) and
> gave it a name (NumOfRows).
>
> I have created Dynamic Named RAnges (for CHARTING) in such a way that
> from a reference cell (Say G5), it will look for the number in
> "NumOfRows" and select as many rows in that column for the graph.
>
> Now I have a need to PASTE the same data in another sheet. I assume
> that for this I need to select an exact sized range to paste the named
> range (correct me if I am wrong)
>
> I am using the following code but it does not work. Where am I going
> wrong?
>
> Thanks in advance for your help.
>
> Best
> Prasad
> **********************
> Sub Test()
> Worksheets("Data").Select
> Range("J4").Select
> ActiveCell.FormulaR1C1 = "X Range"
> Range("J4").Select
> 'NumOfRows is my NAmed RAnges for the cell called
> ActiveCell.Offset(1, 0).Resize(Range("NumOfRows").Value, 0).Select
> Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> End Sub
> *********************************
>

 
Reply With Quote
 
EE
Guest
Posts: n/a
 
      19th Jan 2008
On Jan 18, 4:06*pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:
> Now I have a need to PASTE the same data in another sheet. I assume
> that for this I need to select an exact sized range to paste the named
> range (correct me if I am wrong)
>
> If you copy the entire row then you must paste into a range beginning in
> column A and far enough from the bottom of the sheet for all the rows to fit.
> *However, if your range copied is less than an entire row and less than an
> entire column, then you just have to make sure that there is enough space
> available, it does not have to be exact, just big enough.
>
> If you wanted to copy rows 2 - 6 then from sheet1 to sheet2 then
>
> Worksheets("Sheet1").Rows(2:6).EntireRow.Copy _
> Worksheets("Sheet2").Range("A2")
>
> This would all be one line in VBA and would copy the five rows from sheet1
> to the same location on sheet 2. *It has to be anchored in Column A.
>
> Worksheets(1).Range("A2:F6").Copy Worksheets(2).Range("C7")
>
> This line would copy a 6 x 6 range of cells from sheet1 and paste it into
> sheet2 with the top left corner anchored in Cell C7, or to Range("C7:H13")
>
> When you copy and paste, you need to know where your data is going because
> the paste action will overwrite existing data.
>
>
>
> "EE" wrote:
> > Hi all

>
> > I have a database of about 10 rows and 5000 columns (Starting from
> > A5).

>
> > I created a cell (D2) in the file where I enter a number (say 100) and
> > gave it a name (NumOfRows).

>
> > I have created Dynamic Named RAnges (for CHARTING) in such a way that
> > from a reference cell (Say G5), it will look for the number in
> > "NumOfRows" and select as many rows in that column for the graph.

>
> > Now I have a need to PASTE the same data in another sheet. I assume
> > that for this I need to select an exact sized range to paste the named
> > range (correct me if I am wrong)

>
> > I am using the following code but it does not work. Where am I going
> > wrong?

>
> > Thanks in advance for your help.

>
> > Best
> > Prasad
> > **********************
> > Sub Test()
> > Worksheets("Data").Select
> > Range("J4").Select
> > ActiveCell.FormulaR1C1 = "X Range"
> > Range("J4").Select
> > 'NumOfRows is my NAmed RAnges for the cell called
> > ActiveCell.Offset(1, 0).Resize(Range("NumOfRows").Value, 0).Select
> > Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> > End Sub
> > *********************************- Hide quoted text -

>
> - Show quoted text -


Many thanks for your response. Your earlier post definitely simplified
what I cam up with . By about 50% (you converted 10 lines of code I
wrote to achieve the same objective to 5.)

Best
Prasad
 
Reply With Quote
 
EE
Guest
Posts: n/a
 
      19th Jan 2008
On Jan 18, 4:06*pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:
> Now I have a need to PASTE the same data in another sheet. I assume
> that for this I need to select an exact sized range to paste the named
> range (correct me if I am wrong)
>
> If you copy the entire row then you must paste into a range beginning in
> column A and far enough from the bottom of the sheet for all the rows to fit.
> *However, if your range copied is less than an entire row and less than an
> entire column, then you just have to make sure that there is enough space
> available, it does not have to be exact, just big enough.
>
> If you wanted to copy rows 2 - 6 then from sheet1 to sheet2 then
>
> Worksheets("Sheet1").Rows(2:6).EntireRow.Copy _
> Worksheets("Sheet2").Range("A2")
>
> This would all be one line in VBA and would copy the five rows from sheet1
> to the same location on sheet 2. *It has to be anchored in Column A.
>
> Worksheets(1).Range("A2:F6").Copy Worksheets(2).Range("C7")
>
> This line would copy a 6 x 6 range of cells from sheet1 and paste it into
> sheet2 with the top left corner anchored in Cell C7, or to Range("C7:H13")
>
> When you copy and paste, you need to know where your data is going because
> the paste action will overwrite existing data.
>
>
>
> "EE" wrote:
> > Hi all

>
> > I have a database of about 10 rows and 5000 columns (Starting from
> > A5).

>
> > I created a cell (D2) in the file where I enter a number (say 100) and
> > gave it a name (NumOfRows).

>
> > I have created Dynamic Named RAnges (for CHARTING) in such a way that
> > from a reference cell (Say G5), it will look for the number in
> > "NumOfRows" and select as many rows in that column for the graph.

>
> > Now I have a need to PASTE the same data in another sheet. I assume
> > that for this I need to select an exact sized range to paste the named
> > range (correct me if I am wrong)

>
> > I am using the following code but it does not work. Where am I going
> > wrong?

>
> > Thanks in advance for your help.

>
> > Best
> > Prasad
> > **********************
> > Sub Test()
> > Worksheets("Data").Select
> > Range("J4").Select
> > ActiveCell.FormulaR1C1 = "X Range"
> > Range("J4").Select
> > 'NumOfRows is my NAmed RAnges for the cell called
> > ActiveCell.Offset(1, 0).Resize(Range("NumOfRows").Value, 0).Select
> > Selection.Value = Worksheets("SampleData1").Range("XRange").Value
> > End Sub
> > *********************************- Hide quoted text -

>
> - Show quoted text -


My code looked like this. I will change it as per your post now.

****
Sub ScenarioABCDE()
Dim Rng As Variant
Rng = Worksheets("SampleData1").Range("N2")
' The named range was in a different sheet and I did not call that out
earlier.

'Copying XRange

Worksheets("Data").Select
Range("B4").Select
ActiveCell.FormulaR1C1 = "X Range"
Range("B4").Offset(Rng, 0).Select
Selection.Value = Worksheets("SampleData1").Range("XRange").Value
Range("B5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Value = Worksheets("SampleData1").Range("XRange").Value

End Sub
******
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy named range & paste J.W. Aldridge Microsoft Excel Programming 2 8th Oct 2009 04:38 PM
Named range row copy/paste problem John Microsoft Excel Programming 1 2nd Feb 2009 06:27 PM
Copy & Paste Named Range Contents BJ Microsoft Excel Programming 8 1st Aug 2008 07:18 PM
After Copy and Paste, Add to an Existing Named Range Aria Microsoft Excel Programming 4 8th Mar 2007 12:53 AM
paste values from named dynamic range to another worksheet Nate H Microsoft Excel Programming 2 25th Jan 2006 06:50 PM


Features
 

Advertising
 

Newsgroups
 


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