Solved

Copy named range into another worksheet and link the values

Posted on 2011-09-04
4
226 Views
Last Modified: 2012-05-12
Dear Experts:

I would like to achieve the following using VBA:

Copy the named range (workbook level name = MyRange) of the worksheet named 'Data' to the worksheet named 'Results' with the following requirements...

.... Link the values
.... Start the pasting action on cell reference A5 of the 'Results' worksheet.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36481297
One way of doing this is to enter and array formula referencing the name in the Results sheet, as follows:

Sub CopyRange()
    
    Dim wbk As Excel.Workbook
    Dim rngSource As Excel.Range
    Dim rngTarget As Excel.Range
    
    Set wbk = ActiveWorkbook

    Set rngSource = Application.Range("MyRange")
    Set rngTarget = wbk.Worksheets("Results").Cells(1, 5)
    Set rngTarget = rngTarget.Resize(rngSource.Rows.Count, rngSource.Columns.Count)
    
    rngTarget.FormulaArray = "=MyRange"

End Sub

Open in new window

0
 

Author Comment

by:AndreasHermle
ID: 36482598
Hi andrew:

thank you very much for your professional support. This macro works great and will come in handy for me in other applications.

But regrettably I will have to move some parts of the copied array to other locations in the destination sheet and this results in the 'error' message:

'you cannot change part of an array'

So I would be pretty happy if you or somebody else could provide me with another solution to my requirements.

But again, thank you very much for your great support. Your approach is a neat one.

Regards, Andreas
0
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 500 total points
ID: 36482793
I don't like this one so much, but it gives a non-array solution:

Sub CopyRange()
    
    Dim wbk As Excel.Workbook
    Dim rngSource As Excel.Range
    Dim rngTarget As Excel.Range
    
    Set wbk = ActiveWorkbook

    Set rngSource = Application.Range("MyRange")
    Set rngTarget = wbk.Worksheets("Results").Cells(5, 1)
    
    rngSource.Copy
    rngTarget.Worksheet.Activate
    rngTarget.Select
    rngTarget.Worksheet.Paste link:=True
    
End Sub

Open in new window

0
 

Author Comment

by:AndreasHermle
ID: 36485625
Hi andrew:

works like a charm. Thank you very much for your professional help. Regards, Andreas
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question