Use VB to invert ranges

R

rolandover

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!
 
D

Dan R.

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
 
D

Dan R.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top