PC Review


Reply
Thread Tools Rate Thread

Copy and pasting dynamically

 
 
Zarlot531
Guest
Posts: n/a
 
      29th Apr 2007
I know I'm asking a lot of questions, so I'll try to make this my last
one hopefully.

But, how do you copy and paste dynamically?

For example, when preparing to do a pivot table, I have three
worksheets that vary in row length from day to day. I would like to
put all of the data on one sheet obviously so that I can do a pivot
table. But, the row length varies from day to day, so say I am
copying rows from worksheet A to the bottom of the data in worksheet
B. How do you tell VBA to paste it "lower" in the spreadsheet if
there are more rows or higher if there are fewer?

Thanks!

 
Reply With Quote
 
 
 
 
Anant Basant
Guest
Posts: n/a
 
      29th Apr 2007
Hi,

You can use the following code:

Sub myPT()
Dim destSht As Worksheet
Dim srcSht As Worksheet
Dim NextRow As Long

Set destSht = Sheets("Sheet B")
Set srcSht = Sheets("Sheet A")

NextRow = destSht.Cells(destSht.Rows.Count, 1).End(xlUp).Row + 1

'source sheet has a heading that I have to exclude from copy
srcSht.Cells(1).CurrentRegion.Offset(1).Copy

'I can choose to paste values
destSht.Cells(NextRow, 1).PasteSpecial xlPasteAll
End Sub

Regards
Anant

"Zarlot531" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I know I'm asking a lot of questions, so I'll try to make this my last
> one hopefully.
>
> But, how do you copy and paste dynamically?
>
> For example, when preparing to do a pivot table, I have three
> worksheets that vary in row length from day to day. I would like to
> put all of the data on one sheet obviously so that I can do a pivot
> table. But, the row length varies from day to day, so say I am
> copying rows from worksheet A to the bottom of the data in worksheet
> B. How do you tell VBA to paste it "lower" in the spreadsheet if
> there are more rows or higher if there are fewer?
>
> Thanks!
>



 
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 and Pasting worddummy Microsoft Word Document Management 1 19th Dec 2009 06:40 PM
Help with copy and pasting JHL Microsoft Excel Programming 4 20th Apr 2007 01:58 PM
Dynamically pasting function from Visual Basic to Excel cell John Microsoft Excel Programming 2 9th Feb 2004 11:45 PM
Copy and Pasting!!! Someone please help. Sydney Nguyen Windows XP Photos 1 19th Oct 2003 10:23 PM
Copy and Pasting Christy Smith Microsoft Word Document Management 1 12th Aug 2003 08:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:10 AM.