PC Review


Reply
Thread Tools Rate Thread

Copy a worksheet and ensure range names stay local

 
 
Darren Hill
Guest
Posts: n/a
 
      5th Apr 2007
I'm having a problem with the procedure below.

The macro prompts the user to pick a file, and when that file is picked,
the "TestIfLandRecord" cycles through every worksheet in the chosen
workbook - if it finds one or more that fit my criteria, they are
transferred to the current workbook.
Each "landrecord" has numerous references to ranges in other worksheets.
These ranges exist both in their source workbook, and the destination
workbook. If I copied the sheets manually, I'd get a message popping up:
"A range of the same name exists in the destination worksheet, do you you
want to use this name," and I'd click Yes.
But when I run this macro, it seems to be selecting yes for some ranges,
and no for others - some ranges point to the original file, and some
poiint to the new one.
Is there any way to modify this macro to ensure all range references are
properly updated?

Darren
======================================
Sub TransferLandRecordsToThisBook()
Dim wkb As Workbook, ws As Worksheet
Dim NewFN
Dim FileName As String
Application.ScreenUpdating = False
Select Case MsgBox("This will import all Land Records from another file." _
& vbCrLf _
& vbCrLf & "Do you wish to proceed?" _
, vbYesNo Or vbExclamation Or vbDefaultButton2, "Import
Land Records")

Case vbNo
Exit Sub
End Select
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*..xls),
*.xls", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Set wkb = Workbooks.Open(NewFN)

End If

For Each ws In wkb.Worksheets
If TestIfLandRecord(ws, True) Then
ws.Copy Before:=ThisWorkbook.Sheets(1)
End If
Next ws

' need test to ensure same names don't exist

wkb.Close savechanges:=False
Application.ScreenUpdating = True
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
How to transfer/copy range names with a worksheet to a new Excel f DW Microsoft Excel Discussion 5 12th Jan 2008 11:20 PM
Worksheet copy problem - local names Jack Sheet Microsoft Excel Misc 2 2nd Dec 2004 10:02 AM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 2 22nd Sep 2004 03:30 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM
Copy a range from a CSV file in a webpage to my local worksheet Jav Pa Microsoft Excel Programming 4 25th Aug 2004 01:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:06 PM.