Move values from columns to new rows

BioPA

New Member
Joined
Oct 26, 2013
Messages
30
Hello everybody!

I 'd appreciate if somebody helped me on this:

I have N rows of data separated into 4 columns

ABCD
1VALUE1iVALUE1iiVALUE1iiiVALUE1iv
2VALUE2iVALUE2iiVALUE2iiiVALUE2iv
3VALUE3iVALUE3iiVALUE3iiiVALUE3iv
NVALUENiVALUENiiVALUENiiiVALUENiv

<tbody>
</tbody>


I would like to take the values from C and D columns and move them behind
the first 2, so that

AB
1VALUE1iVALUE1ii
2VALUE1iiiVALUE1iv
3VALUE2iVALUE2ii
4VALUE2iiiVALUE2iv
5VALUE3iVALUE3ii
6VALUE3iiiVALUE3iv
7VALUENiVALUENii
8VALUENiiiVALUENiv

<tbody>
</tbody>

So, now we have 2 columns, 2 new inserted rows with the cell values from column C & D.

Is it possible to have a macro for that?
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,372
Office Version
2013
Platform
Windows
Maybe this:
Code:
Sub a939920()
Dim va, vc, i As Long, j As Long

va = Range("A1", Cells(Rows.count, "D").End(xlUp)).Value
ReDim vc(1 To UBound(va, 1) * 2, 1 To 2)
j = 1
For i = 1 To UBound(va, 1)
    vc(j, 1) = va(i, 1)
    vc(j, 2) = va(i, 2)
    vc(j + 1, 1) = va(i, 3)
    vc(j + 1, 2) = va(i, 4)
    j = j + 2
Next
Range("A1", Cells(Rows.count, "D").End(xlUp)).ClearContents
Range("A1").Resize(UBound(va, 1) * 2, 2) = vc

End Sub
 

Forum statistics

Threads
1,082,285
Messages
5,364,287
Members
400,787
Latest member
bs04c

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top