PC Review


Reply
Thread Tools Rate Thread

Copying a range to a separate excel database

 
 
Albert
Guest
Posts: n/a
 
      23rd Jan 2008
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
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      23rd Jan 2008
One way is to delete the first row after the copy/Paste special code

destrange.Entirerow.delete

--

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


"Albert" <(E-Mail Removed)> wrote in message news:BC8AA3BE-00D9-4828-B2AD-(E-Mail Removed)...
> 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

 
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
Excel to PPT macro - help copying excel range and pasting as html in ppt clootey General Discussion 0 12th May 2011 05:21 AM
copying comments in excel to a separate worksheet dmars Microsoft Excel Programming 14 14th Jan 2009 05:59 PM
get range from excel sheet of separate columns using c# =?Utf-8?B?a29ieWNvb2w=?= Microsoft Excel Programming 0 22nd Jun 2006 03:00 PM
Creating an Excel Database in Separate Workbook =?Utf-8?B?QnJpYW4gQw==?= Microsoft Excel Programming 17 16th Feb 2006 10:17 PM
Copying a range from Excel to PPT =?Utf-8?B?a2lybW1s?= Microsoft Powerpoint 2 1st Jun 2005 07:02 AM


Features
 

Advertising
 

Newsgroups
 


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