Hi
I have some data in a Summary sheet which starts in column J and goes up to column AY in a Sheet.
Below is a small sample - just 9 columns and three rows.
The data is in blocks of three different columns ("Location & Dist", "Platform", and "Percentage") - please ignore the numbers, as this is random data. Is there a better way to transpose this data into one column? At present, the code I have only copies specific columns, but the number of columns could change in a future file. So I was wondering how to take that into account? ie is there a way of getting the code to continue copying three blocks of data until it reaches a blank column?
My current process is this:
Go to Sheet 24 (the Summary sheet) copy the block of data in columns J to L, then go to cell A1 in Sheet 1 and paste it. It then covers columns A-C in Sheet 1.
Go back to Sheet 24 (the Summary sheet), copy the next block of data in columns M to O, then go to the bottom of the range of data pasted in Sheet 1 and paste the newly acquired data there.
I'd be grateful for any thoughts? My code is below - I've left in the code that copies columns beyond the number shown above, as the actual file has more columns. But I'd like the code to stop, if I only have 9 columns, or keep on going, if I have more. Please let me know if you want me to clarify anthing. Thanks in advance
I have some data in a Summary sheet which starts in column J and goes up to column AY in a Sheet.
Below is a small sample - just 9 columns and three rows.
The data is in blocks of three different columns ("Location & Dist", "Platform", and "Percentage") - please ignore the numbers, as this is random data. Is there a better way to transpose this data into one column? At present, the code I have only copies specific columns, but the number of columns could change in a future file. So I was wondering how to take that into account? ie is there a way of getting the code to continue copying three blocks of data until it reaches a blank column?
Location & Dist | Platform: C | Percentage | Location & Dist | Platform: PM | Percentage | Location & Dist | Platform: S | Percentage |
Address 1Plt: C | $20,591.00 | 0% | Address 1Plt: PM | $29,787.00 | 0% | Address 1Plt: S | $72,763.00 | 0% |
Address 2Plt: C | $23,003.00 | 0% | Address 2Plt: PM | $92,523.00 | 0% | Address 2Plt: S | $71,299.00 | 0% |
Address 3Plt: C | $82,273.00 | 0% | Address 3Plt: PM | $14,975.00 | 0% | Address 3Plt: S | $87,301.00 | 0% |
| | |
My current process is this:
Go to Sheet 24 (the Summary sheet) copy the block of data in columns J to L, then go to cell A1 in Sheet 1 and paste it. It then covers columns A-C in Sheet 1.
Go back to Sheet 24 (the Summary sheet), copy the next block of data in columns M to O, then go to the bottom of the range of data pasted in Sheet 1 and paste the newly acquired data there.
I'd be grateful for any thoughts? My code is below - I've left in the code that copies columns beyond the number shown above, as the actual file has more columns. But I'd like the code to stop, if I only have 9 columns, or keep on going, if I have more. Please let me know if you want me to clarify anthing. Thanks in advance
VBA Code:
Sub GetPercentageData()
'Sheet24 in the code below is the Summary Sheet
'Sheet 1 is the transposing sheet, where I am pasting data that's in multiple columns in Sheet 24 (the Summary Sheet)
'into one column in the transposing sheet.
'first clear the sheet with the existing percentage data
Sheet1.Activate
Range("A1").CurrentRegion.Select
Selection.ClearContents
Selection.ClearFormats
'then go to the Summary sheet with the percentage data
Sheet24.Activate
'copy the data from the first group in columns J:L.
Range("J15", Range("L15").End(xlDown)).Copy
'paste their unique ID codes and percentage data into your 'transposing' sheet
Sheet1.Activate
Range("A1").PasteSpecial xlPasteValues
'go back to the Summary Sheet (Sheet24) and get the next set of percentage data
Sheet24.Activate
Range("M15", Range("O15").End(xlDown)).Copy
'go to the transposing sheet
Sheet1.Activate
'go to the bottom of the range in Sheet 1 and paste in the newly acquired data
Range("A1").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValues
'back to the Summary sheet
Sheet24.Activate
Range("P15", Range("R15").End(xlDown)).Copy
'transposing sheet
Sheet1.Activate
'go to the bottom of the range in Sheet 1 and paste in the newly acquired data
Range("A1").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValues
End Sub