What is the macro to move data from column to different column and row

matahazel28

New Member
Joined
Aug 28, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Dear all,

I am a beginner here. I would like to ask a help for someone who can help me to solve the problem. I have around 800 data in excel and I want to move data from one column to different column and row.
It is difficult to say here, I will give the example in the table below.

Capture.JPG


Please ignore the colors, they are just marker for easy visualization.
So, I have around 20 data here. I have to "move" data number one "yellow cell" to column (A1), then data number two "blue cell" to column (A1'). After that data number three to column (A1), data number four to column (A1') so on until every data move to column A1 or A1'. Therefore, Every data from odd number moves to column A1 and every data from even number move to column A1'
I have around 800 data and it is impossible to do all manually. It takes many times and energy. Does anyone want to help me how to work efficiently and rapidly? Do I need run some script in Macro?
Please help me.
Thank you for the attention.

EVERY DATA FROM ODD NUMBER MOVES TO COLUMN A1 AND ANY EVEN DATA MOVE TO COLUMN A1'
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You can use a formula:

=INDEX($D$2:$D$20,ROW(D2)*2+COLUMN(D2)-ROW($D$2)-COLUMN($D$2)-1)

Drag across and down until it starts to error.
 
Upvote 0
EVERY DATA FROM ODD NUMBER MOVES TO COLUMN A1 AND ANY EVEN DATA MOVE TO COLUMN A1'. is a tad confusing.
I stand to be corrected but my interpretation is that odd values move to A and even values move to A' ?

Here is vba that should accomplish that, if indeed it is correct.

TEST_MREXCEL.xlsm
ABCD
1InividuAA'Data
21233423
32435634
43137843
54893256
65455678
764432
877613
9856
10989
1144
1276
1345
14
Sheet3


VBA Code:
Sub SortCols()
Dim DatRng() As Variant
Dim Odds As Variant
Dim Evens As Variant
Dim c As Integer
Dim o As Integer
Dim e As Integer

Range("B:C").ClearContents
Lastr = Cells(Rows.Count, 4).End(xlUp).Row
ReDim Odds(Lastr)
ReDim Evens(Lastr)
ReDim DatRng(Lastr)

Odds(0) = "A"
Evens(0) = "A'"

DatRng = Application.Transpose(Range("D2:D" & Lastr))
For c = 1 To UBound(DatRng)
    If DatRng(c) Mod 2 = 0 Then
        e = e + 1
        Evens(e) = DatRng(c)
        Else
        o = o + 1
            Odds(o) = DatRng(c)    
End If
Next c

Range("B1:B" & Lastr) = Application.Transpose(Odds)
Range("C1:C" & Lastr) = Application.Transpose(Evens)

End Sub

Hope that helps.
 
Upvote 0
I am sorry, "EVERY DATA FROM ODD NUMBER MOVES TO COLUMN A1 AND ANY EVEN DATA MOVE TO COLUMN A1'." was a mistake.
But your interpretation is true @Snakehips
I have tried your VBA macro and It worked!
here the example of running
1630205088014.png



Thank you so much for helping me.
Please stay healthy and happy!
 
Upvote 0
I am sorry, I was wrong. But, the sentences about "Therefore, Every data from odd number moves to column A1 and every data from even number move to column A1'" did not mean like your interpretation.

I hope like this
1630215578580.png


data number 1 move to A1 column, data number 2 move to A1' column
data number 3 move to A1 column, data number 4 move to A1' column
data number 5 move to A1 column, data number 6 move to A1' column
so on.....

so, the odd number and even number in this sentence "Therefore, Every data from odd number moves to column A1 and every data from even number move to column A1'" are the number of individu. It was different with your interpretation @Snakehips. Therefore, A1 or A1' column can contain either odd/even values.
Could you please help me to modify your scripts?
Thank you for the kindness.
 
Upvote 0
Ok. @steve the fish was spot on and his formula does the trick.

If you want to tweak my code to do the same thing then just change the line

VBA Code:
If DatRng(c) Mod 2 = 0 Then

to

VBA Code:
If c Mod 2 = 0 Then

Hope that helps.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

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