Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-17-2016, 06:40 AM
SerenityNetworks SerenityNetworks is offline Macro to sort columns Windows 10 Macro to sort columns Office 2016
Advanced Beginner
Macro to sort columns
 
Join Date: May 2005
Location: Allen, Texas, USA
Posts: 37
SerenityNetworks
Question Macro to sort columns

I have an array of about 340 columns wide and 16 rows long. I need to sort (ascending) each column separately (select column, sort a-z, continue with current selection). It will be quite tedious to do the sorting manually for 340 columns, so I was looking to build a macro to do it for me.

I've tried the following, but can't get it debugged. Of course then I also need to add in a loop to go to the next column, repeat, and eventually end the loop when out of columns with content to sort.

Any help in creating the macro will be appreciated, else I'm back to just doing each column manually.

Thanks in advance,
Andrew

Sub DoIt()
ActiveWorkbook.Worksheets("SortIt").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("SortIt").Sort.SortField s.Add Key:=Range(ActiveCell.EntireColumn.Cells(1)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("SortIt").Sort
.SetRange Range(Selection.EntireColumn)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Reply With Quote
 

Tags
macro, sorting columns



Similar Threads
Thread Thread Starter Forum Replies Last Post
.pdf to .xlsx - How to get sort-able columns? CCinPA Excel 0 07-05-2016 08:30 AM
Macro to sort columns Normal sort not bringing along other columns Dave Fraser Excel 2 06-06-2014 11:48 AM
Need help sorting data in columns that will sort by number of Xs brenna.at.work Excel 8 04-12-2014 07:00 AM
quick replace, sort, change columns userman Excel 1 05-01-2012 06:24 AM
Macro to sort columns How to sort table having three columns? Bahir Barak Word 2 01-20-2011 01:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft