Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy named range into another worksheet and link the values

Posted on 2011-09-04
4
Medium Priority
?
228 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

730 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