Data Rebuild

  • Suppose that we have a column including a million rows of texts and numbers sorting irregularly like this:


    h

    d

    s

    23

    c

    45

    33

    s

    n

    98


    As it shown every number value has some texts value in upper rows of it till the next number value. Is there any VBA to sort it in two columns like this?


    23 h

    23 d

    23 s

    45 c

    98 s

    98 n



    Any help would be appreciated.

  • Looping through that many cells will likely be extremely slow


  • Hi to all.

    This is what I came up with, have a try. Paste it wherever you prefer but it has no reference to a specific sheet so, as it is, it works on the activesheet:

  • Try the attached, it will be faster (especially with a large data set). Click the button on the sheet.


    Code assigned to the button

  • You're welcome

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • An alternative to VBA is Power Query. Here is the Mcode and file attached.


    Code
    let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each try Number.From([Column1]) is number otherwise null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Custom] = true then [Column1] else null),
    #"Filled Up" = Table.FillUp(#"Added Custom1",{"Custom.1"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([Custom] = null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"})
    in
    #"Removed Columns"
  • Agreed, if it works for you then Power Query is the way to go

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!