PC Review


Reply
Thread Tools Rate Thread

Copy Range from Open Workbook to Active Workbook

 
 
Forgone
Guest
Posts: n/a
 
      17th Jul 2009
I've created a Macro to copy data from a range in an open workbook
(data source) to an active workbook.
The Macro to do this is located in the source workbook and have
included the syntax below.

Because I've changed the filename the RngToCopy is no longer valid and
I'm hoping that someone can assist in helping me out with what the
syntax should be to prevent it from happening again when the Source
filename is changed.

The End User would open up the relevant workbook for the grant and
call the function. Thus, the grants workbook is the "active workbook"
but as you can see below, I've reference an actual workbook which I
believe isn't the best thing to do.


Ok, I've managed to figure Part A of the problem out, by using the
ThisWorkbook.name

---

Dim RngToCopy As Range
Dim DestCell As Range

Set RngToCopy = Workbooks("GRANT BALANCES - 2008.2009.xls").Worksheets
("Cover") _
.Range("report.cover.range")

Set DestCell = ActiveSheet.Range("B24")

---

It's now......

----

Dim RngToCopy As Range
Dim DestCell As Range
Dim ThisWorkBookName As String

MyWk = ThisWorkbook.Name

Set RngToCopy = Workbooks(MyWk).Worksheets("Cover") _
.Range("report.cover.range")

---

But now I've got this problem.....

---

ActiveCell.Formula = "=VLOOKUP(BProject,'[GRANT BALANCES -
2008.2009.xls]Grants Balance'!$A:$BG,58,FALSE)"
ActiveSheet.Range("B27:F27").Select

----

I would like to know how to get this to work......

Never mind... solved it......

ActiveCell.Formula = "=VLOOKUP(BProject,'[" & MyWk & "]Grants Balance'!
$A:$BG,58,FALSE)"

Even tho I've solved it, I've posted it anyway in the event in may be
of assistance to someene else.
 
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 Active Range from one workbook to another jat Microsoft Excel Programming 1 17th Dec 2009 01:51 AM
Defining a range in a different open workbook from the active one =?Utf-8?B?SldpcnQ=?= Microsoft Excel Programming 1 21st May 2007 06:21 AM
Get range value active workbook on open add-in RB Smissaert Microsoft Excel Programming 2 11th Feb 2005 01:52 PM
copy worksheet from closed workbook to active workbook using vba =?Utf-8?B?bWFuZ28=?= Microsoft Excel Worksheet Functions 6 9th Dec 2004 07:55 AM
Copy a range of cells in an unopened workbook and paste it to the current workbook topstar Microsoft Excel Programming 3 24th Jun 2004 12:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:20 AM.