?
Solved

Excel Copy/Transpose

Posted on 2013-01-14
10
Medium Priority
?
294 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
Independent Software Vendors: 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 1600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

752 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