Results 1 to 4 of 4

Thread: Order multiple texts in "row.cells" in columns

  1. #1
    Banned
    Join Date
    Jul 2017
    Posts
    5
    Rep Power
    0

    Order multiple texts in "row.cells" in columns

    Order multiple texts in "row.cells" in columns as in the attached file.
    Rows and columns can be upto 1000s of any cell length.

    An example file with input and output
    VBA3.xlsx



    https://www.youtube.com/@alanelston2330/featured
    Last edited by DocAElstein; 09-13-2023 at 11:16 AM.

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    Hello vbadumb
    excelfox is a place to further the knowledge of excel: it is for people to get excel help from other people.
    So tell us a bit more about what you are trying to do and why. That might help us to give the best help
    _..Alternatively, if you just want to post anonymous question, best try one of the larger forums in future , like
    mrexcel.com
    or
    excelforum.com




    Here is what you gave as sample data, and wanted results, and macro results: https://excelfox.com/forum/showthrea...ll=1#post15293
    https://excelfox.com/forum/showthrea...ll=1#post15293

    Here is a macro to get you started https://excelfox.com/forum/showthrea...ll=1#post15294 .

    Here is a brief summary of what is going on in the macro that I have done for you
    I capture your data from the first worksheet into an array, arrIn() = WsIn.Range("B1:F5").Value2
    I loop through the header columns, For Clm = 1 To 5 Step 1 , ( and do nothing if any column headers are empty
    If I have a header, then I note that in variable Itms
    I then go down the data rows, For RwDta = 2 To 5 Step 1
    If I don’t have any data in a row , I do nothing. Otherwise I try to fill a string, strOutB , with as much data as is in a cell. I continually add to that string. I separate that data with a line feed ( vbCr & vbLf ) . I could use any character , ( provided its one that doesn’t appear in any data ) , but the line feed is convenient because I could also view my data in a message box or in the immediate window.
    In each loop, I can determine the number of times I need to have the header by the number of elements I get from an array made from strOutB split by the vbCr & vbLf
    The header data wanted in column A of the output goes into a similar string, strOutA


    Please let us know how you get on with it.


    Alan
    Last edited by DocAElstein; 02-12-2021 at 11:10 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  3. #3
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    11
    You can also do this with Power Query (Get and Transform Data). See attached, table at cell D2 of the OutputB sheet. Right-click and choose Refresh to update.
    It doesn't show anything from entirely blank columns.
    Attached Files Attached Files

  4. #4
    Sir Moderator sandy666's Avatar
    Join Date
    May 2018
    Posts
    233
    Rep Power
    6

    Cool

    shorter version with Power Query
    (I assumed your example was representative)
    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        UOC = Table.UnpivotOtherColumns(Source, {"Find word"}, "Attribute", "Value"),
        Split = Table.ExpandListColumn(Table.TransformColumns(UOC, {{"Value", Splitter.SplitTextByDelimiter("| ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Value"),
        Sort = Table.Sort(Split,{{"Attribute", Order.Ascending}, {"Value", Order.Ascending}}),
        RC = Table.RemoveColumns(Sort,{"Find word"})
    in
        RC
    Find word 1Abc 2wer# 3smar Column1 4chris Attribute Value
    AP1k AP1k, 6-9| AP1k, 10-13 2wer# AP1k, 10-13
    ForCome ForCome, 13-19 2wer# AP1k, 6-9
    2wer# Double, 14-16
    Double Double, 14-16 | Double, 14-16| Double, 14-16 Double, 14-16| Double, 14-16 Double, 14-16| Double, 14-16 2wer# Double, 14-16
    2wer# Double, 14-16
    3smar Double, 14-16
    3smar Double, 14-16
    3smar ForCome, 13-19
    4chris Double, 14-16
    4chris Double, 14-16

    Blank columns are removed, if you want use headers of blank columns you'll need to add any single nullable data (eg. 0 or space) to this column in source table then replace it with null in the result table
    btw. to use Power Query you will need XL2016 or higher or XL2010/2013 with PQ add-in
    Last edited by sandy666; 02-11-2021 at 01:54 PM.
    sandy
    I know you know but I forgot my Crystal Ball and don't know what you know also I may not remember what I did weeks, months or years ago so answer asap. Thinking doesn't hurt

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2019, 11:08 PM
  2. VBA Versions of my "Get Field" and "Get Reverse Field" formulas
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 4
    Last Post: 06-02-2017, 06:15 PM
  3. Replies: 1
    Last Post: 02-10-2015, 09:41 AM
  4. Replies: 4
    Last Post: 09-09-2013, 05:13 PM
  5. Ordinal Suffix (i.e., "st", "nd", "rd" and "th")
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 0
    Last Post: 03-20-2012, 03:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •