Solved

Excel Copy/Transpose

Posted on 2013-01-14
10
255 Views
Last Modified: 2013-01-16
Hello,
can you please help with a VB Code.

I tried to put it in color to explain the copy and paste.

The paste starts at A170.

Any help is appreciated.
Sample.xlsx
0
Comment
Question by:Wass_QA
  • 6
  • 4
10 Comments
 
LVL 26

Expert Comment

by:redmondb
Comment Utility
Hi, Wass_QA.

Edit: Corrected.

Please see attached. The code is...
Option Explicit

Sub Copy_Two_Columns()
ThisWorkbook.Sheets("Sheet1").Activate

Range("A7:D138").Copy Destination:=Range("D170")
Range("A7:C138").Copy Destination:=Range("D302")
Range("E7:E138").Copy Destination:=Range("G302")
Range("D4:D6").Copy
Range("A170:C301").PasteSpecial Paste:=xlPasteAll, Transpose:=True
Range("E4:E6").Copy
Range("A302:C433").PasteSpecial Paste:=xlPasteAll, Transpose:=True

Range("C170:C433").Font.Bold = False

Application.CutCopyMode = False

Application.Goto Reference:="R1C1"

End Sub

Open in new window

Regards,
Brian. Sample-V3.xlsm
0
 

Author Comment

by:Wass_QA
Comment Utility
Hello redmondb,
Thanks for your help,

I didn't mean only 2 columns, (this was only an example)
the code should be for the rest of the sheet as well.

Thanks,
0
 
LVL 26

Expert Comment

by:redmondb
Comment Utility
Wass_QA,

OK, I think I see what you mean now.

Couple of questions, please...
(1) Will EE always be the last column?
(2) Will row 138 always be the last row?

Thanks,
Brian.
0
 

Author Comment

by:Wass_QA
Comment Utility
Hello,
no, they differ depends on the client.

thanks again.
0
 
LVL 26

Expert Comment

by:redmondb
Comment Utility
Wass_QA,

I had the attached done before I saw your post. Please check that the principle is correct while I meake the size generic.

A couple of follow ons, please...
(3) If the no, of rows is variable, what about the first destination row? Is that always 170 or is it a set number of rows below the main data?
(4) May I assume that A4:C6 are the only embedded blanks?

Thanks,
Brian.
(5)
Sample-V4.xlsm
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Wass_QA
Comment Utility
Hello,
I tried the code, it works on the sample File.
but, If I remove some Columns or Rows, It still copies more columns.

(3)Is that always 170 or is it a set number of rows below the main data? Correct

(4) May I assume that A4:C6 are the only embedded blanks? Correct

Thanks,
0
 
LVL 26

Expert Comment

by:redmondb
Comment Utility
Thanks, Wass_QA.

If I remove some Columns or Rows, It still copies more columns.
That's what I expected - that version was done before I saw your post about variable columns/rows.

(3)Is that always 170 or is it a set number of rows below the main data? Correct
Which - is it always 170?

Thanks,
Brian.
0
 
LVL 26

Accepted Solution

by:
redmondb earned 400 total points
Comment Utility
Wass_QA,

Please see my previous post - the attached assumes that row 170 is constant.

Regards,
Brian.
Sample-V5.xlsm
0
 

Author Closing Comment

by:Wass_QA
Comment Utility
Excellent help.
Thank you very much.
0
 
LVL 26

Expert Comment

by:redmondb
Comment Utility
Glad to help, Wass_QA!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now