Copy and paste in Excel using Visual Basic scripting?

5 pts.
Tags:
Microsoft Excel
Microsoft Excel macros
VBA
First of all - Thank you.... I receive info in Excel worksheet "A" with columns of variable length which I want to cut and paste into Excel worksheet "B". Worksheet "A" info starts at B:13 and can range in length from 1 to 200 rows or more. I would like to copy this variable length information then paste into worksheet "B" starting at cell B:13 then on down the column. Can anyone provide the code necessary to accomplisht this? Newbie Brian

Answer Wiki

Thanks. We'll let you know when a new response is added.

Why do you need code to do this?

Is the data on worksheet A by itself, and in a contiguous block? If so,

Range(“B13″).CurrentRegion

would return a range reference to your data. If there are blanks, then

Range(Range(“B13″), Range(“B” & Rows.Count).End(xlUp))

will return a range reference to your data.

To copy and paste it, use this:

Dim rng As Excel.Range
Dim wksBook As Excel.Worksheet

Set rng = Range(Range(“B13″), Range(“B” & Rows.Count).End(xlUp)) ‘ or Range(“B13″).CurrentRegion
Set wksBook = Worksheets(“B”)

rng.Copy wksBook.Range(“B13″)

Enjoy,
JP

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following