Solved

Excel Copy/Transpose

Posted on 2013-01-14
10
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

734 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