Column Copy based on Strings. . .

MagPhun

New Member
Joined
Sep 27, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I need to Loop though each Cell\Column in "Header Template" finding the Value (a String, ignore the Integers used for an Example) in the Cell, then go look on "Original_Data" for the entire Column and Range of used Data with that name, then paste it on "Formatted_Data".
Problem is, on the "Original_Data" Sheet, the Columns are a mess and the Organization of them is random. It's not a 1:1 Ratio, so I need to search for String of the Column name of a Template and find my Data on "Original_Data".
I'm trying to get my Data into MATLAB as cleanly as possible. The m Fig I wrote is very picky.

Anyone help in the right Direction. I have no idea where to even begin. VLOOKUP doesn't work for this.
 

Attachments

  • Data Sheet.PNG
    Data Sheet.PNG
    46.3 KB · Views: 14
  • Formatted for MATLAB.PNG
    Formatted for MATLAB.PNG
    60.5 KB · Views: 15
  • Template EX,PNG.PNG
    Template EX,PNG.PNG
    41.5 KB · Views: 15

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Assuming that you have the latest update of Office 365, you can try and see if the following formula works for you.

With the Original_Data sheet being:
Book1.xlsb
AB
1
2Unit
3357.73
4367.26
5403.49
6407.16
7400.29
8394.21
9390.48
10392.62
11390.87
12358.1
13370.66
14389.72
15388.79
16386.88
17384.57
18382.84
19386.2
20391.79
21391.5
22390.61
23390.04
24388.37
25383.24
26378.76
27378.21
28376.61
29377.69
Original_Data

The header template being:
Book1.xlsb
ABCDEFG
1388.79400.29376.61389.72378.21407.16390.04
2
3
Header Template

And the desired cell to paste the data Formatted_Data sheet being Cell B3 (if not, just copy and paste this formula into the desired cell . . . and no need to carry the formula down. It will size to the data appropriately.),
Book1.xlsb
ABC
1
2
3376.61
4378.21
5388.79
6389.72
7390.04
8400.29
9407.16
10
11
12
Formatted_Data
Cell Formulas
RangeFormula
B3:B9B3=LET( colB,Original_Data!B:B, firstRow,3, lastRow,MAX(IF(colB<>"",ROW(colB))), data,INDEX(colB,firstRow):INDEX(colB,lastRow), row_1,'Header Template'!1:1, firstColumn,1, lastColumn,MAX(IF(row_1<>"",COLUMN(row_1))), searchRange,INDEX(row_1,1,firstColumn):INDEX(row_1,1,lastColumn), searchResult,SORT(TOCOL(IF(data=searchRange,data,""))), r,"------------------Result is below-----------------", FILTER(searchResult,searchResult<>"") )
Dynamic array formulas.


Notes:
  • This will not remove duplicate values.
  • But it will list them in ascending order. (If you don't want this, just remove SORT( and it's closing ).
  • It dynamically counts how many non-blank cells are in the searchRange (row 1 of "Header Template") and how many non-blank cells are in the data (column B of "Original_Data"), where it assumes the firstRow and firstColumn to select/search values from to be what they are initialized to in the top half of the formula. (It will automatically find the last non-blank cells, that doesn't need to be specified.)
  • You can remove the line
    Excel Formula:
        r,"------------------Result is below-----------------",
    , as it's just to let you know that all of the lines above it are calcualtions stored to variables, and the final calculation is below it. (Look up the LET function.)
  • You may also shortern the variable names and/or remove spaces and returns, should you have trouble seeing the entire formula on your screen.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,173
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