Solved

Excel Copy/Transpose

Posted on 2013-01-14
10
264 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:W.E.B
  • 6
  • 4
10 Comments
 
LVL 26

Expert Comment

by:redmondb
ID: 38776208
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:W.E.B
ID: 38776290
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
ID: 38776338
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:W.E.B
ID: 38776352
Hello,
no, they differ depends on the client.

thanks again.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38776410
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:W.E.B
ID: 38776454
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
ID: 38776525
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
ID: 38776535
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:W.E.B
ID: 38776544
Excellent help.
Thank you very much.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38785164
Glad to help, Wass_QA!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
macro for active word document 4 38
Tags from access to excel 3 26
Problem to With line 4 37
excel connection properties parameters grayed out 5 25
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

932 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

13 Experts available now in Live!

Get 1:1 Help Now