pasting data into a

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Pasting Data Into A New Sheet without Overlapping | Excel forum

Pasting Data Into A New Sheet without Overlapping | Excel forum

resolvedResolved · High Priority · Version 2010

Mark has attended:
Excel VBA Intro Intermediate course
Excel Advanced - For Power Users course
Excel PowerPivot course
Excel Dashboards for Business Intelligence course

Pasting Data Into A New Sheet without Overlapping

Hi,

I'm trying to write a sub routine that will copy a column of data and paste it into a separate worksheet, however, I want it to count the number of columns in the new sheet and then paste it into the next empty column. So far my code is very simple (below);

Windows("MB of Anywhere").Activate
Columns("D:D").Select
Selection.Copy
Windows("MA Summary Totals v2").Activate
Columns("B:B").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

What I think I need to do is where the line of code is Columns("B:B").Select I need to have something that counts the columns and then does a +1 to then put it into an empty column.

Thanks
Mark

RE: Pasting Data Into A New Sheet without Overlapping

Hi Mark,

Thank you for the forum question.

You will need to count the number of columns you have in the currentregion in the destination sheet and add one. Store this information in a variable (iCol in my example).

Please have a look at the code below:

Dim iCol As Integer '(variable to store number of column +1)


Sheets(1).Select '(source sheet)
Columns("b").Copy '(column to copy)
Sheets(2).Select '(Destination sheet)


iCol = Range("a5").CurrentRegion.Columns.Count + 1
ActiveSheet.Columns(iCol).Select

ActiveSheet.Paste

I hope the code make sense but please let me know if you need more explanation.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Tue 2 Dec 2014: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Quick Zooming in Excel with rollerball mouses

To zoom in and out of your page hold down the control key and roll the wheel up and down. This will zoom up and down 15% at a time.

View all Excel hints and tips


Server loaded in 0.07 secs.