ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Use VB to invert ranges (https://www.excelbanter.com/excel-programming/399361-use-vbulletin-invert-ranges.html)

rolandover

Use VB to invert ranges
 
Hello all, I am new to using groups for help. Please forgive me
because this will be wordy.

I have a scenario in which I need to take a single row in Excel, which
contains multiple connected values, along with a unique ID, e.g.

A B C D E F G H
I
1234 AA 23874 BB 2893 CC 58374 DD 29834

Column A would be the unique ID, and the following columns would
contain the connected values. So column B would be connected to column
C, column D connected to E, so on and so forth up to 12 possible
connections, equalling 24 columns.

I need to invert this into a vertical format. The final result would
for the above example would be:

A B C
1234 AA 23874
1234 BB 2893
1234 CC 58374
1234 DD 29834

I am very much a beginner with VBA. I would like to keep this as
simple as possible because I will be leaving my current position
sometime in the next few months and would like to have this in place
for my team before I leave. Thanks!


Dan R.

Use VB to invert ranges
 
It's a little sloppy but here's one way:

Sub test()
Dim countD As Integer, countR As Integer

countD = 2
countR = 4

Do Until Cells(1, countR) = ""
Cells(1, countR).Cut Cells(countD, 2)
Cells(1, countR + 1).Cut Cells(countD, 3)
countR = countR + 2
countD = countD + 1
Loop

End Sub

--
Dan Oakes


Dan R.

Use VB to invert ranges
 
Missed the first column...

Sub test()
Dim countD As Integer, countR As Integer

countD = 2
countR = 4

Do Until Cells(1, countR) = ""
Range("A1").Copy Cells(countD, 1)
Cells(1, countR).Cut Cells(countD, 2)
Cells(1, countR + 1).Cut Cells(countD, 3)
countR = countR + 2
countD = countD + 1
Loop

End Sub

--
Dan Oakes



All times are GMT +1. The time now is 06:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com