SOLVED

Large amount of data sorting

%3CLINGO-SUB%20id%3D%22lingo-sub-1414125%22%20slang%3D%22en-US%22%3ELarge%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414125%22%20slang%3D%22en-US%22%3E%3CP%3EPlease%2C%20help.%3C%2FP%3E%3CP%3ENeed%20to%20sort%20numeric%20data%20contained%20in%20large%20numbers%20(several%20thousand)%20strings.%3C%2FP%3E%3CP%3EThe%20data%20in%20each%20string%20must%20be%20sorted%20separately.%3C%2FP%3E%3CP%3EHow%20can%20this%20be%20done%20quickly.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1414125%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414137%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414137%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eit%20might%20be%20difficult%20to%20visualize%20what%20you%20are%20trying%20to%20achieve%20without%20showing%20a%20sample%20data.%20Are%20you%20able%20to%20show%20a%20sample%20data%20after%20removing%20sensitive%20information%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414152%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414152%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F622486%22%20target%3D%22_blank%22%3E%40wumolad%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Odintsov_Maksim_0-1590273923378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F194102iD2503DC914DB9F51%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Odintsov_Maksim_0-1590273923378.png%22%20alt%3D%22Odintsov_Maksim_0-1590273923378.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414212%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414212%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20it%20possible%20to%20explain%20the%20exact%20procedure%20to%20perform%20to%20differentiate%20the%20unsorted%20cases%20and%20sorted%20cases%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20do%20you%20need%20to%20delete%20some%20rows%20or%20columns%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20are%20you%20sorting%20column%20or%20row%20wise%3F%20Somehow%20difficult%20to%20understand%20what%20your%20intention%20is.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414432%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414432%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20SortAllRows()%0A%0ADim%20LRow%20%20%20%20As%20Long%0ADim%20i%20%20%20%20%20%20%20As%20Long%0ADim%20MyRow%20%20%20As%20Range%0ADim%20MyKey%20%20%20As%20Range%0A%0AWith%20ThisWorkbook.Worksheets(%22Sheet1%22)%0A%20%20%20%20LRow%20%3D%20.Cells(.Rows.Count%2C%201).End(xlUp).Row%0A%20%20%20%20For%20i%20%3D%201%20To%20LRow%0A%20%20%20%20%20%20%20%20Set%20MyRow%20%3D%20.Range(%22B1%3AI1%22).Offset(i%20-%201%2C%200)%0A%20%20%20%20%20%20%20%20Set%20MyKey%20%3D%20Application.Index(MyRow%2C%201)%0A%20%20%20%20%20%20%20%20MyRow.Sort%20Key1%3A%3DMyKey%2C%20Order1%3A%3DxlAscending%2C%20Orientation%3A%3DxlLeftToRight%0A%20%20%20%20Next%20i%0AEnd%20With%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414527%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414527%22%20slang%3D%22en-US%22%3EI'm%20sorting%20cases%20in%20each%20rows%20separately.%3CBR%20%2F%3EIn%20other%20words%2C%20this%20is%20sorting%20columns%2C%20but%20only%20within%20each%20individual%20row.%3CBR%20%2F%3EThe%20task%20to%20delete%20something%20is%20absent.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414533%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414533%22%20slang%3D%22en-US%22%3EIs%20this%20a%20VB%20code%3F%20Will%20it%20work%20like%20a%20macro%2C%20can%20I%20include%20it%20in%20an%20existing%20macro%20in%20edit%20mode%3F%3CBR%20%2F%3EWill%20this%20sort%20the%20cases%20in%20each%20row%20as%20I%20described%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414570%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414570%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20it's%20VBA.%20Of%20course%20it%20can%20be%20incorporated%20within%20an%20existing%20procedure%20that%20you%20have%2C%20though%20I'd%20suggest%20testing%20it%20as%20a%20standalone%20macro%20first%2C%20to%20check%20it's%20giving%20you%20the%20desired%20results.%20Currently%20it%20is%20set%20up%20to%20work%20on%20ranges%20beginning%20with%20B1%3AI1%20and%20successive%20rows%2C%20just%20as%20per%20your%20screenshot.%20Obviously%20amend%20as%20required.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1415139%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1415139%22%20slang%3D%22en-US%22%3EYes%2C%20thanks%2C%20the%20code%20works.%20But%20the%20process%20stops%20when%20only%20empty%20cells%20are%20present%20in%20the%20sorting%20range.%3CBR%20%2F%3EIt%20would%20be%20better%20to%20establish%20control%20of%20macro%20completion%20by%20column%20%22A%22%2C%20in%20which%20there%20are%20always%20values.%20How%20to%20do%20it%3F%3CBR%20%2F%3EAnd%20further.%20Perhaps%20the%20macro%20could%20be%20improved%20if%20there%20is't%20specify%20a%20specific%20sorting%20range%2C%20but%20the%20current%20row%20as%20a%20whole.%20And%20is%20it%20possible%20not%20to%20specify%20the%20sheet%20name%20so%20that%20the%20macro%20runs%20on%20any%20Excel%20sheet%3F%3CBR%20%2F%3EI%20am%20not%20good%20in%20VBA%20syntax%2C%20sorry.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1415164%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1415164%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERe%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22%3CEM%3Ethe%20process%20stops%20when%20only%20empty%20cells%20are%20present%20in%20the%20sorting%20range.%20It%20would%20be%20better%20to%20establish%20control%20of%20macro%20completion%20by%20column%20%22A%22%2C%20in%20which%20there%20are%20always%20values.%3C%2FEM%3E%22%2C%20I'm%20confused%3A%20it%20is%20precisely%20column%20A%20which%20controls%20completion%20of%20the%20macro%3A%20the%20code%20I%20supplied%20will%20process%20all%20rows%20%3CSTRONG%3Efrom%20row%201%20up%20to%20the%20row%20in%20the%20worksheet%20which%20contains%20the%20last%20non-blank%20entry%20in%20column%20A%3C%2FSTRONG%3E.%20As%20such%2C%20I'm%20not%20sure%20what%20you%20mean%3A%20did%20you%20change%20anything%20in%20the%20code%20I%20provided%3F%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3ERe%20%22%3CEM%3EPerhaps%20the%20macro%20could%20be%20improved%20if%20there%20is't%20specify%20a%20specific%20sorting%20range%2C%20but%20the%20current%20row%20as%20a%20whole.%22%26nbsp%3B%3C%2FEM%3EI%20would%20never%20code%20a%20macro%20to%20process%20more%20cells%20than%20are%20necessary%2C%20and%20certainly%20not%20an%20entire%20row's%20worth%20(16384%20cells).%20If%20the%20last%20column%20to%20be%20processed%20is%20subject%20to%20change%2C%20this%20can%20be%20detected%20as%20part%20of%20the%20macro%2C%20which%20is%20far%20better%20than%20blanket-setting%20it%20to%20the%20very%20end%20of%20the%20worksheet.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERe%20%22%3CEM%3EAnd%20is%20it%20possible%20not%20to%20specify%20the%20sheet%20name%20so%20that%20the%20macro%20runs%20on%20any%20Excel%20sheet%3F%3C%2FEM%3E%22%20Absolutely.%20If%20you%20could%20clarify%20the%20confusion%20re%20my%20first%20point%20above%20with%20respect%20to%20your%20not%20thinking%20the%20process%20is%20controlled%20by%20the%20entries%20in%20column%20A%20then%20I'll%20happily%20post%20a%20revised%20version%20of%20the%20code.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EPerhaps%20you%20should%20consider%20posting%20an%20actual%20workbook%20(with%20dummy%20data%20as%20opposed%20to%20real%20data%2C%20if%20necessary).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERegards%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417550%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417550%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F676180%22%20target%3D%22_blank%22%3E%40Jos_Woolley%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417556%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417556%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F676180%22%20target%3D%22_blank%22%3E%40Jos_Woolley%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAbout%20the%20first%20point.%20Sorry%2C%20I%20made%20a%20mistake.%20Everything%20works.%3CBR%20%2F%3ERegarding%20the%20second%20point.%20I%20did%20not%20mean%20expanding%20the%20diapason%20of%20cells%20to%20the%20maximum%20size%2C%20but%20using%20a%20function%20such%20as%20selecting%20a%20row%20(shift%20%2B%20space%20from%20the%20keyboard)%20and%20sorting%20with%20a%20heading%20from%20column%20%22A%22.%20Maybe%20I'm%20wrong%2C%20and%20in%20macros%20it's%20better%20not%20to%20do%20that.%3CBR%20%2F%3EExample%20attached%20below.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417603%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417603%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20entirely%20sure%20what%20you%20mean%20there%2C%20sorry.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20modified%20version%20below%20detects%20the%20last%20non-empty%20cell%20in%20each%20row%20and%20applies%20the%20sort%20on%20a%20range%20with%20that%20cell%20as%20the%20upper%20bound.%20Note%20that%2C%20if%20any%20of%20the%20blank%20cells%20in%20your%20range%20in%20fact%20contain%20the%20null%20string%20(%22%22)%2C%20e.g.%20as%20a%20result%20of%20formulas%20within%20those%20cells%2C%20then%20it%20will%20not%20give%20correct%20results%20-%20in%20that%20case%20let%20me%20know%20and%20I%20will%20modify%20the%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20also%20amended%20it%20so%20that%20it%20runs%20on%20whichever%20is%20the%20active%20sheet%20at%20the%20time%20of%20running.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20SortAllRows()%0A%0ADim%20LRow%20%20%20%20As%20Long%0ADim%20i%20%20%20%20%20%20%20As%20Long%0ADim%20MyRow%20%20%20As%20Range%0ADim%20MyCol%20%20%20As%20Long%0ADim%20MyKey%20%20%20As%20Range%0A%0AWith%20ActiveSheet%0A%20%20%20%20LRow%20%3D%20.Cells(.Rows.Count%2C%201).End(xlUp).Row%0A%20%20%20%20For%20i%20%3D%203%20To%20LRow%0A%20%20%20%20%20%20%20%20MyCol%20%3D%20.Cells(i%2C%20.Columns.Count).End(xlToLeft).Column%0A%20%20%20%20%20%20%20%20If%20MyCol%20%26lt%3B%26gt%3B%201%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20MyRow%20%3D%20.Cells(i%2C%202).Resize(%2C%20MyCol%20-%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20MyKey%20%3D%20Application.Index(MyRow%2C%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20MyRow.Sort%20Key1%3A%3DMyKey%2C%20Order1%3A%3DxlAscending%2C%20Orientation%3A%3DxlLeftToRight%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%20i%0AEnd%20With%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1418529%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1418529%22%20slang%3D%22en-US%22%3EWell%20thank%20you.%3CBR%20%2F%3EIt%20works.%3CBR%20%2F%3EOnly%20one%20problem.%3CBR%20%2F%3EColumn%20%22A%22%20contains%20the%20numbering%20of%20records.%20And%20column%20%E2%80%9CA%E2%80%9D%20should%20not%20be%20involved%20in%20the%20sorting%20procedure.%20The%20data%20from%20column%20%22A%22%20should%20always%20remain%20in%20the%20same%20place.%3CBR%20%2F%3ERegards%2C%20thanks%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1418686%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1418686%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EColumn%20A%20should%20not%20be%20affected%20whatsoever%20by%20the%20macro%20I%20posted.%20Can%20you%20post%20a%20workbook%20with%20an%20example%20in%20which%20column%20A%20is%20affected%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1418807%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1418807%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F676180%22%20target%3D%22_blank%22%3E%40Jos_Woolley%3C%2FA%3E%26nbsp%3BFile%20attached%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1418847%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1418847%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677964%22%20target%3D%22_blank%22%3E%40Odintsov_Maksim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EApologies.%20You're%20correct.%20Small%20adjustment%20needed%3A%20change%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EIf%20MyCol%20%26lt%3B%26gt%3B%201%20Then%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Eto%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EIf%20MyCol%20%26gt%3B%202%20Then%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1418881%22%20slang%3D%22en-US%22%3ERe%3A%20Large%20amount%20of%20data%20sorting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1418881%22%20slang%3D%22en-US%22%3EOK%2C%20worked.%3CBR%20%2F%3EWill%20be%20testing.%3CBR%20%2F%3EThank%20you%20so%20much!%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Please, help.

Need to sort numeric data contained in large numbers (several thousand) strings.

The data in each string must be sorted separately.

How can this be done quickly.

16 Replies
Highlighted

Hi @Odintsov_Maksim 

 

it might be difficult to visualize what you are trying to achieve without showing a sample data. Are you able to show a sample data after removing sensitive information?

 

Cheers

Highlighted

@wumolad 

Odintsov_Maksim_0-1590273923378.png

 

Highlighted

Hi @Odintsov_Maksim 

 

Is it possible to explain the exact procedure to perform to differentiate the unsorted cases and sorted cases?

 

For example, do you need to delete some rows or columns? 

 

Also, are you sorting column or row wise? Somehow difficult to understand what your intention is.

 

Cheers

Highlighted

@Odintsov_Maksim 

 

Sub SortAllRows()

Dim LRow    As Long
Dim i       As Long
Dim MyRow   As Range
Dim MyKey   As Range

With ThisWorkbook.Worksheets("Sheet1")
    LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    For i = 1 To LRow
        Set MyRow = .Range("B1:I1").Offset(i - 1, 0)
        Set MyKey = Application.Index(MyRow, 1)
        MyRow.Sort Key1:=MyKey, Order1:=xlAscending, Orientation:=xlLeftToRight
    Next i
End With

End Sub

 

Regards

I'm sorting cases in each rows separately.
In other words, this is sorting columns, but only within each individual row.
The task to delete something is absent.
Highlighted
Is this a VB code? Will it work like a macro, can I include it in an existing macro in edit mode?
Will this sort the cases in each row as I described?
Highlighted

@Odintsov_Maksim 

 

Yes, it's VBA. Of course it can be incorporated within an existing procedure that you have, though I'd suggest testing it as a standalone macro first, to check it's giving you the desired results. Currently it is set up to work on ranges beginning with B1:I1 and successive rows, just as per your screenshot. Obviously amend as required.

 

Regards

 

Highlighted
Yes, thanks, the code works. But the process stops when only empty cells are present in the sorting range.
It would be better to establish control of macro completion by column "A", in which there are always values. How to do it?
And further. Perhaps the macro could be improved if there is't specify a specific sorting range, but the current row as a whole. And is it possible not to specify the sheet name so that the macro runs on any Excel sheet?
I am not good in VBA syntax, sorry.
Highlighted

@Odintsov_Maksim 

 

Re "the process stops when only empty cells are present in the sorting range. It would be better to establish control of macro completion by column "A", in which there are always values.", I'm confused: it is precisely column A which controls completion of the macro: the code I supplied will process all rows from row 1 up to the row in the worksheet which contains the last non-blank entry in column A. As such, I'm not sure what you mean: did you change anything in the code I provided? 

Re "Perhaps the macro could be improved if there is't specify a specific sorting range, but the current row as a whole." I would never code a macro to process more cells than are necessary, and certainly not an entire row's worth (16384 cells). If the last column to be processed is subject to change, this can be detected as part of the macro, which is far better than blanket-setting it to the very end of the worksheet.

 

Re "And is it possible not to specify the sheet name so that the macro runs on any Excel sheet?" Absolutely. If you could clarify the confusion re my first point above with respect to your not thinking the process is controlled by the entries in column A then I'll happily post a revised version of the code.

 

Perhaps you should consider posting an actual workbook (with dummy data as opposed to real data, if necessary).

 

Regards

Highlighted

@Jos_Woolley 

About the first point. Sorry, I made a mistake. Everything works.
Regarding the second point. I did not mean expanding the diapason of cells to the maximum size, but using a function such as selecting a row (shift + space from the keyboard) and sorting with a heading from column "A". Maybe I'm wrong, and in macros it's better not to do that.
Example attached below.

Highlighted

@Odintsov_Maksim 

 

Not entirely sure what you mean there, sorry.

 

The modified version below detects the last non-empty cell in each row and applies the sort on a range with that cell as the upper bound. Note that, if any of the blank cells in your range in fact contain the null string (""), e.g. as a result of formulas within those cells, then it will not give correct results - in that case let me know and I will modify the code.

 

I have also amended it so that it runs on whichever is the active sheet at the time of running.

 

Sub SortAllRows()

Dim LRow    As Long
Dim i       As Long
Dim MyRow   As Range
Dim MyCol   As Long
Dim MyKey   As Range

With ActiveSheet
    LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    For i = 3 To LRow
        MyCol = .Cells(i, .Columns.Count).End(xlToLeft).Column
        If MyCol <> 1 Then
            Set MyRow = .Cells(i, 2).Resize(, MyCol - 1)
            Set MyKey = Application.Index(MyRow, 1)
            MyRow.Sort Key1:=MyKey, Order1:=xlAscending, Orientation:=xlLeftToRight
        End If
    Next i
End With

End Sub

 

Regards

Highlighted
Well thank you.
It works.
Only one problem.
Column "A" contains the numbering of records. And column “A” should not be involved in the sorting procedure. The data from column "A" should always remain in the same place.
Regards, thanks
Highlighted

@Odintsov_Maksim 

 

Column A should not be affected whatsoever by the macro I posted. Can you post a workbook with an example in which column A is affected?

 

Regards

Highlighted

@Jos_Woolley File attached

Highlighted
Solution

@Odintsov_Maksim 

 

Apologies. You're correct. Small adjustment needed: change

 

If MyCol <> 1 Then

to

If MyCol > 2 Then

 

Regards

 

 

Highlighted
OK, worked.
Will be testing.
Thank you so much!