Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default copy and paste problem in vb

I have a sheet called DrListWorkCopy which data i would like to duplicate in
DrListWorkCopy1. DrLIstWorkCopy1 exists as an empty sheet with headers on row
1 identical to DrLIstWorkCopy. The Macro works well when there is data in
DrListWorkCopy. However, in the occasion when DrListWorkCopy happen to have
no data in it, the macro coppies the headers and paste it onto
DrListWorkCopy1.

How do I prevent that? I think it has got to do with how I coded the last
empty row in DrListWorkCopy1.

The codes are as follows:

Dim SourceWks As Worksheet
Dim TargetWks As Worksheet

Set SourceWks = Sheets("DrListWorkCopy")
Set TargetWks = Sheets("DrListWorkCopy1")

SourceWks.Range("A2:AS" & SourceWks.Range("AS65536").End(xlUp).Row).Copy
TargetWks.Select
Range("A2").Select
TargetWks.Paste

Would appreciate some help.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default copy and paste problem in vb

Try the following, the lines that end with ". _" (dot, space, underscore) are
valid VBA line breaks to compensate for any errant word wrapping:

Dim wsSource As Worksheet
Dim wsTarget As Worksheet

Set wsSource = ThisWorkbook.Worksheets("DrListWorkCopy")
Set wsTarget = ThisWorkbook.Worksheets("DrListWorkCopy1")
wsSource.Range(.Range("A2:AS" & SourceWks. _
Range("AS65536").End(xlUp).Row).Copy). _
Copy Destination:=wsTarget.Range("A2")

Set wsSource = Nothing
Set wsTarget = Nothing

--
Kevin Backmann


"Blubber" wrote:

I have a sheet called DrListWorkCopy which data i would like to duplicate in
DrListWorkCopy1. DrLIstWorkCopy1 exists as an empty sheet with headers on row
1 identical to DrLIstWorkCopy. The Macro works well when there is data in
DrListWorkCopy. However, in the occasion when DrListWorkCopy happen to have
no data in it, the macro coppies the headers and paste it onto
DrListWorkCopy1.

How do I prevent that? I think it has got to do with how I coded the last
empty row in DrListWorkCopy1.

The codes are as follows:

Dim SourceWks As Worksheet
Dim TargetWks As Worksheet

Set SourceWks = Sheets("DrListWorkCopy")
Set TargetWks = Sheets("DrListWorkCopy1")

SourceWks.Range("A2:AS" & SourceWks.Range("AS65536").End(xlUp).Row).Copy
TargetWks.Select
Range("A2").Select
TargetWks.Paste

Would appreciate some help.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default copy and paste problem in vb

Thanks Kevin,

I copy and paste the codes and ran out of room in the posting box. Thats not
a problem.

Problem is logic. It could be the "xlup" . When the SourceWks is empty, it
copies the headers because that happens to be the last row with data.

I want to find a way to prevent that.



"Kevin B" wrote:

Try the following, the lines that end with ". _" (dot, space, underscore) are
valid VBA line breaks to compensate for any errant word wrapping:

Dim wsSource As Worksheet
Dim wsTarget As Worksheet

Set wsSource = ThisWorkbook.Worksheets("DrListWorkCopy")
Set wsTarget = ThisWorkbook.Worksheets("DrListWorkCopy1")
wsSource.Range(.Range("A2:AS" & SourceWks. _
Range("AS65536").End(xlUp).Row).Copy). _
Copy Destination:=wsTarget.Range("A2")

Set wsSource = Nothing
Set wsTarget = Nothing

--
Kevin Backmann


"Blubber" wrote:

I have a sheet called DrListWorkCopy which data i would like to duplicate in
DrListWorkCopy1. DrLIstWorkCopy1 exists as an empty sheet with headers on row
1 identical to DrLIstWorkCopy. The Macro works well when there is data in
DrListWorkCopy. However, in the occasion when DrListWorkCopy happen to have
no data in it, the macro coppies the headers and paste it onto
DrListWorkCopy1.

How do I prevent that? I think it has got to do with how I coded the last
empty row in DrListWorkCopy1.

The codes are as follows:

Dim SourceWks As Worksheet
Dim TargetWks As Worksheet

Set SourceWks = Sheets("DrListWorkCopy")
Set TargetWks = Sheets("DrListWorkCopy1")

SourceWks.Range("A2:AS" & SourceWks.Range("AS65536").End(xlUp).Row).Copy
TargetWks.Select
Range("A2").Select
TargetWks.Paste

Would appreciate some help.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Paste problem Ian_Add Excel Discussion (Misc queries) 3 January 11th 08 02:47 PM
Copy and paste problem Germano Excel Discussion (Misc queries) 1 August 24th 07 12:45 PM
Copy and Paste Problem Skc Excel Discussion (Misc queries) 1 March 8th 06 07:21 PM
copy paste problem? Neil22 Excel Discussion (Misc queries) 5 January 10th 06 05:32 PM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM


All times are GMT +1. The time now is 04:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"