Jump to content

Excel Help - Sort Data

Go to solution Solved by Zando_,
15 minutes ago, manikyath said:

you're not gonna do this with formula's.

Just did. Sort of. 

 

Changed the values to be unique so it's easier to see what it's doing: 

278819402_Screenshot2023-01-18at4_46_59PM.png.b051a42c1952075103b10ce3d65cd532.png

 

For this to work, you do need the DataPoint # to be working though. And you will need to manually drag the header # column out for as many datapoints as you have (if you grab a few cells then drag to fill, excel will notice you're counting up one by one and continue it for you). Does also use an INDEX formula which can get pretty performance heavy depending on how big your data set is IIRC, I've only lightly mucked about with them. Then you use this formula and it works:

86961476_Screenshot2023-01-18at4_48_35PM.png.c7f25d01e298b6d53d04138abe655420.png

 

=INDEX($B$2:$B$10,MATCH(CONCAT($D$2," ",E2),$B$2:$B$10,0)+1,0) if you want to paste it in, you add +2 instead of +1 after the MATCH function for the 2nd row (MQ3). This will break the instant the format changes or again, if the Datapoint # isn't working. 

 

Best solution is what @Kilrahsaid, make it spit out a CSV. 

 

Hi, I'm trying to organise my Arduino sensor data into a graph but am struggling with cleaning up the data. This is a sample of the raw data

 

 image.png.8785902779d4c886d8241eeb2ec8cb2f.png#

 

I want excel to separate this into a heading, and two variables. (Datapoint is supposed to go up by 1 every time it checks the sensor again, but havent got that code working yet)

This is what I want to turn it into automatically somehow

image.png.aa50b7f6e9111da69a50723a076bd110.png

I want to do this so I can get a nice graph with 2 lines for the different sensors (MQ2 and MQ3)

image.png.df174e3fc15b14f1bddccd4d3f6407c4.png

 

Any help is greatly appreciated

Please tag me @RTX 3090 so I can see your reply

Link to comment
https://linustechtips.com/topic/1482338-excel-help-sort-data/
Share on other sites

Link to post
Share on other sites

Make your code write out the data in csv format.

Header with titles, then one line per point with the values.

 

Datapoint,MQ2,MQ3
0,234,134
1,245,21
2,21,356

Then you can import that into excel directly and graph the columns.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
https://linustechtips.com/topic/1482338-excel-help-sort-data/#findComment-15757651
Share on other sites

Link to post
Share on other sites

15 minutes ago, manikyath said:

you're not gonna do this with formula's.

Just did. Sort of. 

 

Changed the values to be unique so it's easier to see what it's doing: 

278819402_Screenshot2023-01-18at4_46_59PM.png.b051a42c1952075103b10ce3d65cd532.png

 

For this to work, you do need the DataPoint # to be working though. And you will need to manually drag the header # column out for as many datapoints as you have (if you grab a few cells then drag to fill, excel will notice you're counting up one by one and continue it for you). Does also use an INDEX formula which can get pretty performance heavy depending on how big your data set is IIRC, I've only lightly mucked about with them. Then you use this formula and it works:

86961476_Screenshot2023-01-18at4_48_35PM.png.c7f25d01e298b6d53d04138abe655420.png

 

=INDEX($B$2:$B$10,MATCH(CONCAT($D$2," ",E2),$B$2:$B$10,0)+1,0) if you want to paste it in, you add +2 instead of +1 after the MATCH function for the 2nd row (MQ3). This will break the instant the format changes or again, if the Datapoint # isn't working. 

 

Best solution is what @Kilrahsaid, make it spit out a CSV. 

 

Gaming PC NAS Laptop Workstation

CPU: i5 12600KF 6P+4E Ryzen 7 3700X M4 SoC 4P+6E Xeon X5690 6c12t

Cooler: Noctua NH-D15S Wraith Stealth w/NF-A9 Passive Apple CPU Cooler

Motherboard: ASRock Z690 ITX/ax ASUS Pro B550M-C/CSM Apple J713AP Mac-F221BEC8 (Mac Pro 5,1)

RAM: 2x16GB 3600Mhz DDR4 2x16GB 2400MHz DDR4 24GB Micron LPDDR5 4x8GB 1333MHz ECC DDR3

GPU: Sapphire Pulse Radeon 9060 XT 16GB Radeon WX2100 M4 SoC 10C Radeon RX 5700

Storage: 1TB MP34 + 2TB P41 500GB SSD + 2x4TB IronWolf Pro in ZFS Mirror Apple AP0512Z 1TB Crucial MX500

ODD: LG WH14NS40 None LG GP65NB60 USB DVD Writer Don't know

PSU: EVGA 850W GM Silverstone SST-TX300 53.8Wh LiPo Battery Delta DPS-980BB

Case: Silverstone Sugo 14 Dell Inspiron 530S Mac16,12 chassis (13" MBA) 2009-2012 Mac Pro "Cheese Grater"

OS: Gentoo Linux TrueNAS Scale macOS 26 Tahoe Fedora Linux

 

Display: LG 27UK650-W (4K 60Hz IPS panel)

Mouse: EVGA X17

Keyboard: Corsair K55 RGB

 

Mobile/Work Devices: 14" M5P MacBook Pro (work) - iPhone 17 Pro - Apple Watch S11

 

Other Misc Devices: iPod Video (Gen 5.5E, iFlash Solo w/128GB SD Card, Rockbox), Nintendo Switch

 

Vehicles: 2002 Ford F150, 2003 Harley-Davidson Sportster 1200, 2022 Kawasaki KLR650, 1994 DR350SE

Link to comment
https://linustechtips.com/topic/1482338-excel-help-sort-data/#findComment-15757662
Share on other sites

Link to post
Share on other sites

1 minute ago, Zando_ said:

 

For this to work, you do need the DataPoint # to be working though. And you will need to manually drag the header # column out for as many datapoints as you have (if you grab a few cells then drag to fill, excel will notice you're counting up one by one and continue it for you). Does also use an INDEX formula which can get pretty performance heavy depending on how big your data set is IIRC, I've only lightly mucked about with them. Then you use this formula and it works:

pretty impressive actually, but you'll still need to find a way to slice the cells in half (the value is only what's after the space) and that's already something i wouldnt want to rely on for larger datasets.

 

either way, you're twisting excel in all sorts of ways that it shouldnt be taken, for something a 5-line python script or VBA script will blast trough in milliseconds.

 

i'm not going to do midnight programming because it'll keep me up all night if i do, but essentially this is a very quick and dirty solution:

- open the source file (i'm assuming a .txt dump from a serial prompt, or a .csv file with horrid formatting)

- open a destination .csv

- prep the destination .csv with "DataPoint <tab> MQ2 <tab> MQ3)

- loop until end of file:

-- read a line into string

-- if string contains 'DataPoint', output newline

-- split the string at space, and output the second segment. then output <tab> (you might have to slice off a newline marking from the string too, not 100% on that)

- after the loop, close the two files, and you're done.

 

the reason i say output a <tab> instead of csv ('comma separated values') is because excel's csv processor expects tabs by default.

 

 

OR.. ofcourse.. arduino sided soluton:

 

instead of printing 3 lines you just do this:

Serial.print(intDataPoint);

Serial.print(',');

Serial.print(intMQ2value);

Serial.print(',');

Serial.print(intMQ3value);

Serial.println();

 

poops out 'correct enough' csv for excel's csv import function to understand. replace commas with tabs for something excel will import more easily.

 

in fact.. i'm pretty sure if you stick spaces in there with the above formatting, arduino IDE's serial monitor will make the graph just off of the data stream.

 

Link to comment
https://linustechtips.com/topic/1482338-excel-help-sort-data/#findComment-15757697
Share on other sites

Link to post
Share on other sites

Assuming you're importing the data like this:

image.png.2570d74f20f61317e9258d0812e83e22.png

 

Then this macro should do the trick.

 

Sub SortData()
    
    Dim arr() As Variant
    arr() = ThisWorkbook.Sheets(1).Range("A1").CurrentRegion.Value2
    
    Dim arraySize As Long
    arraySize = (UBound(arr) / 3) - 1
    
    ReDim arr1(arraySize) As Long, arr2(arraySize) As Long, arr3(arraySize) As Long
    
    Dim i As Long, j As Long
    j = 0
    Dim val() As String
    
    For i = LBound(arr) To UBound(arr)
        
        val = Split(arr(i, 1), " ")
        
        Select Case val(0)
            Case "DataPoint"
                arr1(j) = val(1)
            Case "MQ2"
                arr2(j) = val(1)
            Case "MQ3"
                arr3(j) = val(1)
                j = j + 1
        End Select
        
    Next i
    
    arraySize = arraySize + 1

    With ThisWorkbook.Sheets(1)
        .Range("D1").Resize(, arraySize).Value2 = arr1
        .Range("D2").Resize(, arraySize).Value2 = arr2
        .Range("D3").Resize(, arraySize).Value2 = arr3
    End With
    
End Sub

 

Works like this:

image.gif.4280a8f2ed1e09c2cc10346630d2e582.gif

And now a word from our sponsor: 💩

ℑ𝔣 𝔶𝔬𝔲 𝔬𝔫𝔩𝔶 𝔫𝔬𝔱𝔦𝔠𝔢 𝔭𝔢𝔯𝔣𝔬𝔯𝔪𝔞𝔫𝔠𝔢 𝔭𝔯𝔬𝔟𝔩𝔢𝔪𝔰 𝔴𝔥𝔢𝔫 𝔶𝔬𝔲 𝔥𝔞𝔳𝔢 𝔞 𝔰𝔱𝔞𝔱 𝔠𝔬𝔲𝔫𝔱𝔢𝔯 𝔬𝔳𝔢𝔯𝔩𝔞𝔶 𝔞𝔠𝔱𝔦𝔳𝔢, 𝔶𝔬𝔲 𝔞𝔯𝔢 𝔪𝔢𝔯𝔢𝔩𝔶 𝔩𝔬𝔬𝔨𝔦𝔫𝔤 𝔣𝔬𝔯 𝔭𝔯𝔬𝔟𝔩𝔢𝔪𝔰 𝔱𝔬 𝔟𝔢 𝔲𝔭𝔰𝔢𝔱 𝔬𝔳𝔢𝔯. 𝔗𝔲𝔯𝔫 𝔬𝔣𝔣 𝔱𝔥𝔢 𝔠𝔬𝔲𝔫𝔱𝔢𝔯 𝔟𝔢𝔣𝔬𝔯𝔢 𝔞𝔰𝔨𝔦𝔫𝔤 𝔣𝔬𝔯 𝔥𝔢𝔩𝔭 𝔞𝔫𝔡 𝔰𝔢𝔢 𝔦𝔣 𝔶𝔬𝔲 𝔰𝔱𝔦𝔩𝔩 𝔫𝔬𝔱𝔦𝔠𝔢.

-.-. --- --- .-.. --..-- / -.-- --- ..- / -.- -. --- .-- / -- --- .-. ... . / -.-. --- -.. .

ᑐᑌᑐᑢ

Spoiler

    ▄██████                                                      ▄██▀

  ▄█▀   ███                                                      ██

▄██     ███                                                      ██

███   ▄████  ▄█▀  ▀██▄    ▄████▄     ▄████▄     ▄████▄     ▄████▄██   ▄████▄

███████████ ███     ███ ▄██▀ ▀███▄ ▄██▀ ▀███▄ ▄██▀ ▀███▄ ▄██▀ ▀████ ▄██▀ ▀███▄

████▀   ███ ▀██▄   ▄██▀ ███    ███ ███        ███    ███ ███    ███ ███    ███

 ██▄    ███ ▄ ▀██▄██▀    ███▄ ▄██   ███▄ ▄██   ███▄ ▄███  ███▄ ▄███▄ ███▄ ▄██

  ▀█▄    ▀█ ██▄ ▀█▀     ▄ ▀████▀     ▀████▀     ▀████▀▀██▄ ▀████▀▀██▄ ▀████▀

       ▄█ ▄▄      ▄█▄  █▀            █▄                   ▄██  ▄▀

       ▀  ██      ███                ██                    ▄█

          ██      ███   ▄   ▄████▄   ██▄████▄     ▄████▄   ██   ▄

          ██      ███ ▄██ ▄██▀ ▀███▄ ███▀ ▀███▄ ▄██▀ ▀███▄ ██ ▄██

          ██     ███▀  ▄█ ███    ███ ███    ███ ███    ███ ██  ▄█

        █▄██  ▄▄██▀    ██  ███▄ ▄███▄ ███▄ ▄██   ███▄ ▄██  ██  ██

        ▀███████▀    ▄████▄ ▀████▀▀██▄ ▀████▀     ▀████▀ ▄█████████▄

 

Link to comment
https://linustechtips.com/topic/1482338-excel-help-sort-data/#findComment-15757730
Share on other sites

Link to post
Share on other sites

57 minutes ago, manikyath said:

pretty impressive actually, but you'll still need to find a way to slice the cells in half (the value is only what's after the space) and that's already something i wouldnt want to rely on for larger datasets.

Oh derp, that would be a simple function or two to delete the spaces and 1st 3 characters, but yeah it approaches a nice level of clusterfuckery that snowballs the instant anything changes 😂

Gaming PC NAS Laptop Workstation

CPU: i5 12600KF 6P+4E Ryzen 7 3700X M4 SoC 4P+6E Xeon X5690 6c12t

Cooler: Noctua NH-D15S Wraith Stealth w/NF-A9 Passive Apple CPU Cooler

Motherboard: ASRock Z690 ITX/ax ASUS Pro B550M-C/CSM Apple J713AP Mac-F221BEC8 (Mac Pro 5,1)

RAM: 2x16GB 3600Mhz DDR4 2x16GB 2400MHz DDR4 24GB Micron LPDDR5 4x8GB 1333MHz ECC DDR3

GPU: Sapphire Pulse Radeon 9060 XT 16GB Radeon WX2100 M4 SoC 10C Radeon RX 5700

Storage: 1TB MP34 + 2TB P41 500GB SSD + 2x4TB IronWolf Pro in ZFS Mirror Apple AP0512Z 1TB Crucial MX500

ODD: LG WH14NS40 None LG GP65NB60 USB DVD Writer Don't know

PSU: EVGA 850W GM Silverstone SST-TX300 53.8Wh LiPo Battery Delta DPS-980BB

Case: Silverstone Sugo 14 Dell Inspiron 530S Mac16,12 chassis (13" MBA) 2009-2012 Mac Pro "Cheese Grater"

OS: Gentoo Linux TrueNAS Scale macOS 26 Tahoe Fedora Linux

 

Display: LG 27UK650-W (4K 60Hz IPS panel)

Mouse: EVGA X17

Keyboard: Corsair K55 RGB

 

Mobile/Work Devices: 14" M5P MacBook Pro (work) - iPhone 17 Pro - Apple Watch S11

 

Other Misc Devices: iPod Video (Gen 5.5E, iFlash Solo w/128GB SD Card, Rockbox), Nintendo Switch

 

Vehicles: 2002 Ford F150, 2003 Harley-Davidson Sportster 1200, 2022 Kawasaki KLR650, 1994 DR350SE

Link to comment
https://linustechtips.com/topic/1482338-excel-help-sort-data/#findComment-15757754
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×