Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Copying a range to a separate excel database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Albert - 23 Jan 2008 01:19 GMT
Hi Guys,

I am using Ron de Bruin's code to copy "usedcells" to a excel
database/masterfile.
This is what I got so far:
Sub copy_to_another_workbook()
   Dim sourceRange As Range
   Dim destrange As Range
   Dim destWB As Workbook
   Dim Lr As Long

   Application.ScreenUpdating = False
   If bIsBookOpen("Test DB.xlsm") Then
       Set destWB = Workbooks("Test DB.xlsm")
   Else
       Set destWB = Workbooks.Open("C:\Documents and Settings\albertr\My
Documents\Test Database\Test DB.xlsm")
   End If
   Lr = LastRow(destWB.Worksheets("Sheet1")) + 1
   Set sourceRange =
ThisWorkbook.Worksheets("Sheet1").Range("A1").CurrentRegion
   Set destrange = destWB.Worksheets("Sheet1").Range("A" & Lr)
   sourceRange.Copy
   destrange.PasteSpecial xlPasteValues, , False, False
   Application.CutCopyMode = False
   destWB.Close True
   Application.ScreenUpdating = True
End Sub

The problem I have that when I execute the command the sourcerange is
selected in the destination sheet as this is active
Set sourceRange = ThisWorkbook.Worksheets("Sheet1").Range("A1").CurrentRegion

How can I correct this to copy all used rows except the first row in the
source file and then paste it into the last row of the destination sheet?

Thanks
Albert
Ron de Bruin - 23 Jan 2008 08:18 GMT
One way is to delete the first row after the copy/Paste special code

destrange.Entirerow.delete

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Hi Guys,
>
[quoted text clipped - 34 lines]
> Thanks
> Albert
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.