问题
I have 79 sheets of data which are all the same format.
I would like to copy data from a Column C6:C34 in to a Row in a 'Summary Sheet'.
I have been successful in using the formulas mentioned in this Stackoverflow question here, which suggests
=TRANSPOSE('worksheet A'!A1:A10)
and
=INDEX(A!$A$1:$A$10, COLUMN())
But as far as I can work out, I have to perform the function 79 times for the 2013-14 year, then another 79 times for the 2014-15 year, and so on.
Is there a way that I can take the data from C6:C34 in Sheet1 to Sheet79 and transpose it in to rows D2:AF2 to D80:AF80? I'm pretty computer literate, but haven't got much experience with using macros (read:none).
Any help would be greatly appreciated!
回答1:
I spent a bit of time trying to figure out a way to do this with formulas, but still am empty-handed on that approach (am pretty much a noob when it comes to that). I'd be interested to hear of a way to do it that way!
I wrote how you'd do this in VBA (assuming you're copying TO the first worksheet of the workbook) :
Sub CopyThemAll()
Dim ws As Worksheet, sh As Worksheet, wb As Workbook
Set wb = ThisWorkbook
Set ws = wb.Sheets(1)
currentRow = 2
For Each sh In wb.Sheets
If sh.Name <> ws.Name Then
For x = 6 To 34
ws.Cells(currentRow, x - 2) = sh.Cells(x, 3)
Next x
currentRow = currentRow + 1
End If
Next sh
End Sub
回答2:
After several hours of trying to find a workaround, I worked out how to do this as a formula (and it was stupidly easy).
I went through and copied the =TRANSPOSE('worksheet A'!A1:A10)
formula down each of the 79 rows separately, by dragging across the row so that the number of cells in the row I selected matched the number of cells in the original column in the sheet I was transposing from, copying the relevant formula in to the formula box, then pressing
ctrl + shift+ enter
.
After I had completed the entire summary spreadsheet for 2014/15, I copied it over so that I had the same headings for the 2015/16 summary. In doing so, I realised that the data had updated when I copied it over, so I did a "replace all" of C6:C34 to D6:D34 (which in this case is the data in the 2015/16 column of each of the 79 spreadsheets) and it updated without me having to do anything else!
While I still had to spend some time transposing the data to the first summary sheet, this may be a good alternative for those who, like me, aren't very experienced at macros.
There is a great alternative answer above though if you do know how to use macros.
来源:https://stackoverflow.com/questions/25131131/transpose-data-from-a-specific-column-from-multiple-sheets-to-rows-on-another-s