Hi - I'm new here, and to writing macros, and would really appreciate some help. I'm looking to transpose a set of values as set out below...and just can't make it work.
Query.jpg
Any help would be greatly appreciated.
Hi - I'm new here, and to writing macros, and would really appreciate some help. I'm looking to transpose a set of values as set out below...and just can't make it work.
Query.jpg
Any help would be greatly appreciated.
Apologies, ignore the second image. Ideally, I would like to transpose the values to a new worksheet in the same workbook. Thanks in advance!
This isn't quite the normal transpose, so unless someone else has a better idea, I would use loops to go through the first range and then make the second table. There are faster ways to do this with arrays, but below is one way. Please adapt as needed.
![]()
Please Login or Register to view this content.
bkm2016....you're a hero. Brilliant - I'll tweak this accordingly. Thanks so much.
If data start in A1
and no emty Cells in first Row or first Column
this can do
Kind regards
Leo
Apologies for reopening the thread, however my requirements have changed slightly (set out below). I now need to transpose three cells of data and excluding the 'period' header in the example above. Examples set out below:
From this:
Transposed.PNG
To this:
Book 1 [51863].PNG
Here's the current code:
Sub Data_transpose()
Dim StartRange As Range
Set StartRange = Sheet1.UsedRange
Sheets.Add.Name = "Transposed"
ActiveCell.FormulaR1C1 = "Member Name"
ActiveCell.Interior.ColorIndex = 48
Range("B1").Select
ActiveCell.FormulaR1C1 = "Period"
ActiveCell.Interior.ColorIndex = 48
Range("C1").Select
ActiveCell.FormulaR1C1 = "Amount"
ActiveCell.Interior.ColorIndex = 48
Dim NewStart As Range
Set NewStart = Range("A2")
Dim j As Long
For r = 2 To StartRange.Rows.Count
For i = 2 To StartRange.Columns.Count
If StartRange.Cells(r, i).Value > 0 Then
NewStart.Offset(j).Value = StartRange.Cells(r, 1).Value
NewStart.Offset(j, 1).Value = StartRange.Cells(1, i).Value
NewStart.Offset(j, 2).Value = StartRange.Cells(r, i).Value
j = j + 1
End If
Last edited by TimC1974; 05-30-2017 at 03:19 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks