Sorting<\/p><\/div> \nFor this we need to copy and Paste below Sub Function<\/strong> in the Module of your Excel VBA. Now call this function from which ever sheet you want.<\/p>\n\r\nSub Sorting()\r\n\r\nDim str_array(1000), temp, input_str As String\r\nDim flag As Boolean\r\nflag = False\r\n\r\ninput_str = Range(\"A1\").Value\r\nl = Len(input_str)\r\n\r\n'--- Store complete string in an array format letter by letter\r\n\r\nFor i = 1 To l\r\ntemp = Left(input_str, i)\r\nstr_array(i) = Right(temp, 1)\r\nNext\r\n\r\n'--- We need to Sort all the letters in ascending or Descending Order\r\n'--- For that i will add a Sheet in workbook and copy all the letters in one column and sort it by Excel Sort functionality\r\n\r\nFor Each Sheet In Sheets\r\nIf Sheet.Name = \"config\" Then\r\nflag = True\r\nEnd If\r\nNext Sheet\r\nIf flag = False Then\r\nWorksheets.Add().Name = \"config\"\r\nEnd If\r\n\r\n'--- Select that config Sheet\r\n\r\nWorksheets(\"config\").Activate\r\n\r\nFor i = 1 To l\r\nsrange = \"A\" & i\r\nRange(srange).Value = str_array(i)\r\nNext\r\n\r\n'--- Now Sort that Column with all values\r\n\r\nsrange = \"A1:\" & srange\r\nRange(srange).Select\r\nActiveWorkbook.Worksheets(\"config\").sort.SortFields.Clear\r\nActiveWorkbook.Worksheets(\"config\").sort.SortFields.Add Key:=Range(\"A1\"), SortOn:=xlSortOnValues, _\r\nOrder:=xlAscending, DataOption:=xlSortNormal\r\nWith ActiveWorkbook.Worksheets(\"config\").sort\r\n.SetRange Range(srange)\r\n.Header = xlNo\r\n.MatchCase = False\r\n.Orientation = xlTopToBottom\r\n.SortMethod = xlPinYin\r\n.Apply\r\nEnd With\r\n\r\n'--- After sorting now Store back all the letters in the array variable\r\n\r\nFor i = 1 To l\r\nsrange = \"A\" & i\r\nstr_array(i) = Range(srange).Value\r\nNext\r\nWorksheets(\"Sheet2\").Activate\r\ninput_str = \"\"\r\nFor i = 1 To l\r\ninput_str = input_str & str_array(i)\r\nNext\r\n\r\n'--- Put the sorted String in your cell where you want\r\n\r\nRange(\"A2\").Value = input_str\r\n\r\n'--- Delete that config file now\r\n\r\nApplication.DisplayAlerts = False\r\nWorksheets(\"config\").Delete\r\nApplication.DisplayAlerts = True\r\n\r\nEnd Sub\r\n\r\n\r\n<\/code><\/pre>\n<\/span>","protected":false},"excerpt":{"rendered":"Dear Readers, By using Excel Macro, we can sort a String which is stored in a Cell in an Excel Sheet. Sorting will be done as a String. For example (Ascending): First all Numeric Values in ascending Order then Special Chars then Alphabets in ascending etc. For this we need to copy and Paste below […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1246,1682],"tags":[],"class_list":["post-12086","post","type-post","status-publish","format-standard","hentry","category-macro","category-popular-articles"],"yoast_head":"\n
Sorting a String stored in a cell of Excel - Let's excel in Excel<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n