Transpose and copy data every 23 lines with VBA loop!

curtitoo

New Member
Joined
Jul 14, 2011
Messages
1
Hello,

I am quite the noob when it comes to VBA and am using someone elses code to be somewhat modified to fit my needs (unsuccessfully).

Here's my situation. I have a pretty big file that i want *certain fields (unique ID's)* of the data within 1 row to be transposed into one column and that same row (excluding the just transposed data) to be copied 23 times (so 24 total because of the original one). So my goal here is to match up that redundant data of 24 rows with the Unique ID's. So in essance i want to create duplicate entries EXCEPT for the Unique ID's per every entry. I want to run this for every 24 rows as it represents a different entity every 24 rows. Thanks in advance and I will attach an example of what i mean.

Things to keep in mind:





I was thinking maybe something like this:


Sub test()
Dim lngLastRow As Long, lngLastCol As Long, lngLoopRow As Long, lngWriteRow As Long
Dim lngLoopCol As Long, wsWriteSheet As Worksheet
Set wsWriteSheet = Sheets("Sheet1")
'Starts transpose at line (look at the next line)
lngWriteRow = 2
With Sheets("Sheet1")
lngLastRow = .Range("A" & Rows.Count).End(xlUp).Row

For lngLoopRow = 1 To lngLastRow

lngLastCol = .Cells(lngLoopRow, Columns.Count).End(xlToLeft).Column

For lngLoopCol = 2 To lngLastCol

'wsWriteSheet.Range("A" & lngWriteRow) = .Cells(lngLoopRow, 1)
wsWriteSheet.Range("B" & lngWriteRow) = .Cells(lngLoopRow, lngLoopCol)
lngWriteRow = lngWriteRow + 1

Next lngLoopCol

Next lngLoopRow

End With
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,216,079
Messages
6,128,687
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top