Switch data between columns on same row

Alt F11

New Member
Joined
Jan 31, 2025
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
I hope someone wants to help me...

I need a macro to "reorder" data in column A and B to new columns (on a new sheet) per unique value on the same row! The data below is just simplified to understand my question but in reality the data is more various than only three different single characters. Forget the collors i used in both of the Mini Sheets (Before and After), it's only necessary to reorder the data (column E/F and G/H belongs to eachother). I need this to be able to select data for a line graph where all samples of the same species are placed in the same columns. In reality it will not be two columns before the macro is executed, but perhaps five to ten, so the output is most likely also more than three columns to... ?

Thank you in advance!

BeforeAfter
ABEtc.ABCEtc.
......
Columnheaders ->​
xyz
1xy1xy
2xz2xz
3yz3yz
4zx4xz
5zx5xz
6yz6yz

Table_View_Data_II.xlsm
ABCDEFGHIJKL
1TimeServing Cell DL EARFCN_Serving Cell IdentityServing Cell RSRP (dBm)Neighbor Cell DL EARFCN: N1_Neighbor Cell Identity: N1Neighbor Cell RSRP (dBm): N1Neighbor Cell DL EARFCN: N2_Neighbor Cell Identity: N2Neighbor Cell RSRP (dBm): N2
211:30:27.0002850_61-106.42994_32-105.0100_44-110.1
311:30:29.0002850_61-106.72994_32-109.1100_44-111.0
411:30:31.0002850_61-106.62994_32-110.0100_44-112.0
511:30:33.0002850_61-106.32994_32-105.0100_44-111.2
611:30:35.0002850_61-106.52994_32-110.2100_44-111.3
711:30:37.0002850_61-106.71500_151-101.62994_32-104.2
811:30:39.0002850_61-107.12994_32-102.71500_151-109.5
911:30:41.0002850_61-106.42994_32-110.3100_44-111.6
1011:30:43.0002850_61-106.12850_158-110.42994_32-111.1
1111:30:45.0002850_61-106.31500_151-107.12994_32-110.1
1211:30:47.0002850_61-106.31500_151-102.92994_32-112.0
1311:30:49.0002850_61-103.2__
1411:30:51.0002850_61-102.2__
1511:30:53.0002850_61-102.5__
1611:30:55.0002850_61-102.5__
1711:30:57.0002850_61-102.2__
1811:30:59.0002850_61-102.5__
1911:31:01.0002850_61-102.1__
2011:31:03.0002850_61-102.1__
2111:31:05.0002850_61-102.0__
2211:31:07.0002850_61-101.4__
2311:31:09.0002850_61-101.2__
2411:31:11.0002850_61-102.5__
2511:31:13.0002850_61-103.1__
2611:31:15.0002850_61-102.9__
2711:31:17.0002850_61-103.1__
2811:31:19.0002850_61-103.0__
2911:31:21.0002850_61-102.3__
Before


Table_View_Data_II.xlsm
ABCDEFGHIJKL
1TimeServing Cell DL EARFCN_Serving Cell IdentityServing Cell RSRP (dBm)2994_32100_441500_1512850_158
211:30:27.0002850_61-106.42994_32-105.0100_44-110.1
311:30:29.0002850_61-106.72994_32-109.1100_44-111.0
411:30:31.0002850_61-106.62994_32-110.0100_44-112.0
511:30:33.0002850_61-106.32994_32-105.0100_44-111.2
611:30:35.0002850_61-106.52994_32-110.2100_44-111.3
711:30:37.0002850_61-106.72994_32-104.21500_151-101.6
811:30:39.0002850_61-107.12994_32-102.71500_151-109.5
911:30:41.0002850_61-106.42994_32-110.3100_44-111.6
1011:30:43.0002850_61-106.12994_32-111.12850_158-110.4
1111:30:45.0002850_61-106.32994_32-110.11500_151-107.1
1211:30:47.0002850_61-106.32994_32-112.01500_151-102.9
1311:30:49.0002850_61-103.2__
1411:30:51.0002850_61-102.2__
1511:30:53.0002850_61-102.5__
1611:30:55.0002850_61-102.5__
1711:30:57.0002850_61-102.2__
1811:30:59.0002850_61-102.5__
1911:31:01.0002850_61-102.1__
2011:31:03.0002850_61-102.1__
2111:31:05.0002850_61-102.0__
2211:31:07.0002850_61-101.4__
2311:31:09.0002850_61-101.2__
2411:31:11.0002850_61-102.5__
2511:31:13.0002850_61-103.1__
2611:31:15.0002850_61-102.9__
2711:31:17.0002850_61-103.1__
2811:31:19.0002850_61-103.0__
2911:31:21.0002850_61-102.3__
After
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi Alt F11,

Why use vba instead of a formula? If you can use both, I would choose only formula like so:

Classeur1
ABCDEFGH
1TimeServing Cell DL EARFCN_Serving Cell IdentityServing Cell RSRP (dBm)Neighbor Cell DL EARFCN: N1_Neighbor Cell Identity: N1Neighbor Cell RSRP (dBm): N1Neighbor Cell DL EARFCN: N2_Neighbor Cell Identity: N2Neighbor Cell RSRP (dBm): N2
211:30:27.0002850_61-106.4000015258792994_32-105100_44-110.099998474121
311:30:29.0002850_61-106.6999969482422994_32-109.099998474121100_44-111
411:30:31.0002850_61-106.5999984741212994_32-110100_44-112
511:30:33.0002850_61-106.3000030517582994_32-105100_44-111.199996948242
611:30:35.0002850_61-106.52994_32-110.199996948242100_44-111.300003051758
711:30:37.0002850_61-106.6999969482421500_151-101.5999984741212994_32-104.199996948242
811:30:39.0002850_61-107.0999984741212994_32-102.6999969482421500_151-109.5
911:30:41.0002850_61-106.4000015258792994_32-110.300003051758100_44-111.599998474121
1011:30:43.0002850_61-106.0999984741212850_158-110.4000015258792994_32-111.099998474121
1111:30:45.0002850_61-106.3000030517581500_151-107.0999984741212994_32-110.099998474121
1211:30:47.0002850_61-106.3000030517581500_151-102.9000015258792994_32-112
1311:30:49.0002850_61-103.199996948242__
1411:30:51.0002850_61-102.199996948242__
1511:30:53.0002850_61-102.5__
1611:30:55.0002850_61-102.5__
1711:30:57.0002850_61-102.199996948242__
1811:30:59.0002850_61-102.5__
1911:31:01.0002850_61-102.099998474121__
2011:31:03.0002850_61-102.099998474121__
2111:31:05.0002850_61-102__
2211:31:07.0002850_61-101.400001525879__
2311:31:09.0002850_61-101.199996948242__
2411:31:11.0002850_61-102.5__
2511:31:13.0002850_61-103.099998474121__
2611:31:15.0002850_61-102.900001525879__
2711:31:17.0002850_61-103.099998474121__
2811:31:19.0002850_61-103__
2911:31:21.0002850_61-102.300003051758__
before


Classeur1
ABCDEFGH
1TimeServing Cell DL EARFCN_Serving Cell IdentityServing Cell RSRP (dBm)2994_321500_1512850_158100_44
211:30:27.0002850_61-106.400001525879-105  -110.099998474121
311:30:29.0002850_61-106.699996948242-109.099998474121  -111
411:30:31.0002850_61-106.599998474121-110  -112
511:30:33.0002850_61-106.300003051758-105  -111.199996948242
611:30:35.0002850_61-106.5-110.199996948242  -111.300003051758
711:30:37.0002850_61-106.699996948242-104.199996948242-101.599998474121  
811:30:39.0002850_61-107.099998474121-102.699996948242-109.5  
911:30:41.0002850_61-106.400001525879-110.300003051758  -111.599998474121
1011:30:43.0002850_61-106.099998474121-111.099998474121 -110.400001525879 
1111:30:45.0002850_61-106.300003051758-110.099998474121-107.099998474121  
1211:30:47.0002850_61-106.300003051758-112-102.900001525879  
1311:30:49.0002850_61-103.199996948242    
1411:30:51.0002850_61-102.199996948242    
1511:30:53.0002850_61-102.5    
1611:30:55.0002850_61-102.5    
1711:30:57.0002850_61-102.199996948242    
1811:30:59.0002850_61-102.5    
1911:31:01.0002850_61-102.099998474121    
2011:31:03.0002850_61-102.099998474121    
2111:31:05.0002850_61-102    
2211:31:07.0002850_61-101.400001525879    
2311:31:09.0002850_61-101.199996948242    
2411:31:11.0002850_61-102.5    
2511:31:13.0002850_61-103.099998474121    
2611:31:15.0002850_61-102.900001525879    
2711:31:17.0002850_61-103.099998474121    
2811:31:19.0002850_61-103    
2911:31:21.0002850_61-102.300003051758    
after
Cell Formulas
RangeFormula
B1:D29B1=before!B1:D29
E1:H1E1=UNIQUE(TEXTSPLIT(TEXTJOIN(";",TRUE,FILTER(before!E2:E29,before!E2:E29<>"_"),FILTER(before!G2:G29,before!G2:G29<>"_")),";",,TRUE),TRUE)
E2:H29E2=IFERROR(INDEX(before!$E$1:$H$29,ROW(),MATCH(E$1,before!$E2:$H2,0)+1),"")
Dynamic array formulas.



HOW DOES IT WORK??

In befor sheet, you can copy/paste your cells with time, serving cell DL and RSRP or with this:
Excel Formula:
=before!B1:D29

Next, we have the unique header that we get with this function:
Excel Formula:
=UNIQUE(TEXTSPLIT(TEXTJOIN(";",TRUE,FILTER(before!E2:E29,before!E2:E29<>"_"),FILTER(before!G2:G29,before!G2:G29<>"_")),";",,TRUE),TRUE)

Finaly, in each cell with a header and a time, you can put this one and drag it accross the table. it will try to find the header value for the specific row the cell is at, and return the column number. Then we offset with the +1 and the index function is going to get the value of that specific cell. If nothing is found, then it will be empty ("").
Excel Formula:
=IFERROR(INDEX(before!$E$1:$H$29,ROW(),MATCH(E$1,before!$E2:$H2,0)+1),"")

Bests regards,

Vincent
 
Upvote 0

Forum statistics

Threads
1,226,116
Messages
6,189,057
Members
453,524
Latest member
AshJames

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