Sorting VBA Array On Worksheet On Two Columns?
Aug 30, 2013
I'm trying to sort an array which is of variable height/rows when put on a worksheet. I need to sort by column C ascending (smallest to largest) and then by column D ascending (oldest to newest). I tried recording a macro but the code is just junk.
Code:
Dim BookSPSortingWorksheet As Worksheet
Dim TR As Range
Set BookSPSortingWorksheet = ThisWorkbook.Worksheets.Add
Set TR = BookSPSortingWorksheet.Range("A1").Resize(UBound(array_book_SPNames), UBound(array_book_SPNames, 2))
TR = array_book_SPNames
Is there a way I can use the sort function like the below by indexing my TR range for columns 3 and 4?
Code:
TR.Sort key1:=TR, order1:=xlAscending, MatchCase:=False
View 3 Replies
ADVERTISEMENT
Sep 16, 2005
I have an array that is 10 rows by 4 columns. I would like to sort the whole array based on sorting column 1 in descending order. Any good ideas to edit or write new code? Anything to send me in the right direction would be sweet as well!
View 9 Replies
View Related
Feb 28, 2007
Im working on a project where a spreadsheet holds data which is spread over multiple rows. The number of rows can change depending on the case.
Imagine 1 case being 1 row of certain details, then a various number of rows below detailing some different information in different columns.
A crude example is this: ...
View 9 Replies
View Related
Mar 17, 2014
I'm trying to sort a table as displayed in the image below. The table consisting of items in column A, here fruits, and a column E where totals over three month is displayed.
I have entered an array formula in column H where the total of each fruit is summed and then sorted in descending order. My problem is that whenever two fruits have equal value (here, apple and pear), Excel will not manage the display of both fruits, it will just display the first twice. The formula in column I is a simple SUMIFS.
It doesn't matter if Apple or Pear is displayed first, but I need both items to be displayed in column H.
excel1.png
View 5 Replies
View Related
Dec 19, 2013
Have an array that contains file names similar to these:
\serversharesmysharesomefolder3_s6_macro_cycle22_2Ft10p75.txt
\serversharesmysharesomefolder1_s6_macro_cycle22_2Ft10p75.txt
\serversharesmysharesomefolder25_s6_macro_cycle22_2Ft10p75.txt
\serversharesmysharesomefolder32_s6_macro_cycle22_2Ft10p75.txt
I need to sort the array in ascending order based on the file name. The file name is after the last “” and starts with a number(s). From my example above I would like the resulting sort order to look like this:
\serversharesmysharesomefolder1_s6_macro_cycle22_2Ft10p75.txt
\serversharesmysharesomefolder3_s6_macro_cycle22_2Ft10p75.txt
\serversharesmysharesomefolder25_s6_macro_cycle22_2Ft10p75.txt
\serversharesmysharesomefolder32_s6_macro_cycle22_2Ft10p75.txt
I want to use the Application.GetOpenFilename to populate the array and then process the filenames.
I assumed you data starts in "A1"
Results start "F1"
Code:
Sub MG19Dec38()
Dim varFiles As Variant ' used to hold array of file to open
Dim ray
Dim j As Long, i As Long
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Tem As String
' ray = Application.GetOpenFilename("Txt Files (*.txt), *.txt", , , , True)
View 2 Replies
View Related
Jul 15, 2009
I have a report to compile where i have a master list of data with three columns.
A=Name B=Type C=Location
I have 3 Types to sort. These being D, E, F
I need to sort into three new worksheets from the first sheet the D's into one, the E's into another and the F's
into the last.
I have over 3000 different A's to sort by the Type.
View 9 Replies
View Related
Nov 6, 2007
Is there a code or some way for me to sort 4 columns together? I want to sort a list of employees and for each employee theres a column with their Lost Business, customer satisfaction, and two more columns. I want to sort all the columns at the same time so that the best employees overall will go to the top of the list and the worst ones will be at the bottom. Whenever I use the sorting feature it does each column independant of the others so everytime I sort a new column it just moves around the last one I sorted.
View 14 Replies
View Related
Oct 6, 2009
Im not entirely sure about this but it seems like if I have data in columns A - Z and sort in one of them, the data in Columns AA - AZ does not move accordingly rather it stays fixed.
View 4 Replies
View Related
Apr 13, 2007
I have a spreadsheet that is populated my Concatinating data from other worksheets. Some of the results are numbers, some is data while others are blank spaces and othersare set by the concactenating default of "" when the criteria is not met. I need to sort these colums. However it seems that the default "" from the formula is not a BLANK or a ZERO or an empty cell.
Those cells will place themselves at the top of the sort. I need to eliniate them. I have copied and pasted as values but that has no effect. Ironically I can identify the cells with an if statement so what I need help with is generating a macro that will cycle thru the range of results and delete the approriate cells.
I have tried the following:
lr = Range("A1").End(xlDown).Row ' Last Row
lc = Range("A1").End(xlToRight).Column ' Last Column
For Each cell In Range(Cells(1, 1), Cells(lc, lr))
cell.Select
AC = ActiveCell
If AC = "" Then Selection.Delete Shift:=xlUp
Next
But this does not work as it cycles top to bottom and leaves behind 1/2 the problem cells.
View 7 Replies
View Related
Oct 28, 2009
This might sound like a weird question, but is there any way to prohibit a user to using the sort function in a particular sheet?
Filtering for values is okay but sorting must be prohibited so that no rows "change place" in a sense.
View 4 Replies
View Related
Aug 14, 2014
I have an issue with some data that I need to sort into several columns. Basically, I have a column that has data listed in each cell like this; A 567 T 1 D3. What I want to be able to do is sort that data into several columns. I am not sure how to do this at all. I have attached my data to be looked at. I have already started the process but manually, and I don't feel like having to do this manually as this is very time consuming considering I am trying to sort the data into ~1927 rows and 5 columns.
View 2 Replies
View Related
Aug 5, 2009
I need help with either a formula or macro for sorting data into specific columns. I need the entries under the headings Ar,Bj... to be sorted into the correct columns. To add to the problem, the data may not be exactly the same as the heading.
Attached is an simple example of a spreadsheet where the top is the original and the bottom is what I need the final outcome to be. The data is pasted from a different spreadsheet and will be changing each time.
View 12 Replies
View Related
Sep 3, 2009
I have a potential of 5 columns of numerical data (simple number entries) which are entered manually in no particular order.
Is there any way of sorting the data so that it is presented in numerical order (smallest to largest) starting with the smallest figure at the start of column 1 up to the largest figure at the end of column 5.
View 11 Replies
View Related
Oct 15, 2009
I have three columns, one column is time every two seconds with data associated that time, and one is time every minute with an associated tidal height.
I want to sort my data so that for every 2 seconds I have an associated tidal height for that minute.
eg:
what I have:
Time Time Tidal Height
(2 sec intervals) (min) (meters)
1:15:00 1:15 1.342
1:15:02 1:16 1.221
1:15:04 1:17 1.115
...
1:15:58 1:43 0.024
1:15:60 1:44 0.012
1:16:00 1:45 0.008 ....................
View 2 Replies
View Related
Jul 23, 2013
I am trying to 'stagger sort' multiple columns, but am having some difficulties.Ex.
Say A and B are lists of part no and C is data corresponding to column B. I have:
A B C
1 2 .
2 3 ,
4 4 ;
5 7 '
8 9 "
I want:
A B C
1 _ _
2 2 .
_ 3 ,
4 4 ;
5 _ _
_ 7 '
8 _ _
_ 9 "
(the _ are just supposed to be empty place holders, without them I have formatting issues)
Is there a 'quick' way to sort them this way?I am attaching the actual file that I am working with.
View 9 Replies
View Related
Sep 8, 2008
How do I sort multiple columns at once? In other words, I have a chart that is a series of 1s and 2s, and I need all of the 1s to drop to the bottom, so that I can do a rudimentary chart in spreadsheet form. My chart has dozens of columns like so:
1 2 1 1 1 2 2 2 2
1 2 1 1 2 1 1 2 2
2 1 2 2 2 2 2 2 2
1 1 1 2 1 1 1 1 2
How do I get the entire range sorted to look like this, without having to do each column individually (hours of work)?:
2 2 2 2 2 2 2 2 2
1 2 1 2 2 2 2 2 2
1 1 1 1 1 1 1 2 2
1 1 1 1 1 1 1 1 2
View 9 Replies
View Related
Jan 14, 2009
I have some data that is 300 rows x 43 columns.
I'd like to sort the 43 colums by using some of the rows. Is this possible using normal excel?
Alternatively is there a simple way to sort the colums in VBA?
View 9 Replies
View Related
Jan 13, 2008
how to sort based on the first two digit..
I need to sort the COMM CODE ( which is at Column no 3 )
View 14 Replies
View Related
Jan 14, 2009
I need to do sorting and filtering the similar records to new worksheet. I need you help to do this job, give some idea or command to use for the following steps.
I have attached the worksheet newtran.xls.
1. I need to find the last column, the column will be increased or decreases. so that we need to find the last column at time of running the macro. Now the value is there till column DD
2. I need to concatenate the column B, D, F to last column find out at 1 step. Insert a new column and place the concatenated value.
3. Entire row will be Sorted based on concatenated value column.
4. Find the similar row on concatenated column and entire row need to be moved to new worksheet.
View 11 Replies
View Related
Feb 21, 2010
I have the attached workbook that contains a list of produce in the Produce sheet and I am wanting to have the Availability sheet show what produce is available each day sorted into Good, Limited and None as per the data on the Produce sheet. I should end up with a list of each type of produce listed under the relevant availability each day.
Sorry but I have limited knowledge of VB, I assume that the best way to do this is some code behind the Availability worksheet but I am not able to determine what this code should look like.
View 9 Replies
View Related
Apr 21, 2009
I have a workbook with two worksheets.
Worksheet one is "Company ID" info, in it are the columns:"Company Name", "street add", "city", "state".
Worksheet two is "Company Contact Person" in it are the columns: a reference to worksheet one column one "Company Name", and column two is 'Contact Person name'.
I want to be able to sort worksheet one at will, By city, or state, or any of the various columns. When sorting worksheet one I want the relationships in worksheet to to remain intact.
"Company Name" - "Company Contact Person".
View 6 Replies
View Related
Dec 27, 2006
I have a worksheet thats makes things easier by sorting to users needs. heproblem I have is I have totals in columns p:AJ rows 1:3. How can I prevent the user of sorting the whole worksheet. Most of my users have basic Excell understanding so sorting is usually the whole page. I've tried hiding and protecting the columns but must be doing some thing wrong. I just need them to only be able to sort column A:N. I'm already working on moving totals to a separate sheet to I know this will work but curious for future worksheets.
View 3 Replies
View Related
Jun 14, 2014
I'm managing a World Cup Prediction League and have been trying to create a spreadsheet that will eventually feed in to a league, positioning each player in descending order. However, I would like to use three columns to determine how to position the players.
EG.
Priority 1 - Column D - Total Points (Rank from Highest to Lowest)
(if there are players with equal Total Points in column D, then)
Priority 2 - Column F - Correct Scores (Rank from Highest to Lowest
(if there are still players with equal value after Total Points and Correct Scores, then)
Priority 3 - Column F - Incorrect Scores (Lowest to Highest)
I've tried for hours to work this out but can't. It would save me hours of work each day
I have attached the document : WC Prediction League EXAMPLE.xlsx
View 14 Replies
View Related
Nov 25, 2009
I have two sets of 2 columns. One column in one set is identical to a column in the other set, but they are arranged in different orders. I would like arrange those two columns side by (matching their numbers) so that I can find the average of the two non-identical columns.
View 2 Replies
View Related
May 23, 2013
I'm trying to sort by City first, then by Report #, but keeping the highlighted rows together. If I use the custom sort it will through my D2's at the bottom and not keep them with their city, report, and D1. How do I get them to stay together? I have attached my document example.
View 4 Replies
View Related
Jun 20, 2013
In Column A there are randomly assigned numbers using the RANDBETWEEN function.
In Column B there are three possible values X, Y, and Z.
I want to create a sort order where "X" is always at the top but then the rest of the rows are randomly sorted by column A (Y and Z values are intermixed).
Currently I tried to use a Custom List and the value is "X" to sort first, and then a seconday sort of Column A. The problem is that column B is always sorted by X then Y then Z where I am trying to get the Y and Z values to be randomly intermixed based on the sort of the random numbers in Column A.
I know I can manually do 2 seperate sorts each time, but I would like to save a sort list to the file so I recreate that sort over and over again.
View 3 Replies
View Related
Mar 11, 2014
I need sorting a contact list of 3000 + so the emails match with the company name, and first and last name of the contacts
Column A is Email and Matches column C & D. Column B matches with Column E. I need A to match with B-E.
I've attached an example : Example Spreadsheet.xls
View 2 Replies
View Related
Jan 20, 2009
I have a worksheet with columns of Unique Words and corresponding Frequency of Occurrence for several years. I would like to sort the data so the rows match up on same Unique Words across years.
I am using Excel 2007.
View 9 Replies
View Related
Feb 20, 2009
I have a spreadsheet on lets say 10 columns, now col 1 and 9 are locked so they cant be selected. Col 2-8 can be sorted by selecting them, but information in col 10 does not sort.
Question is there a way of connecting the cells in col 10 to the cell in lets say col 2, so thay when you sort the rows and cols between 2 and 8, the cells on col 10 are sorted as well As i have noticed you cant sort two differenr selections...???
View 2 Replies
View Related
Oct 3, 2011
Excel 2007 - Sorting across columns
Need to sort part of an Excel worksheet across multiple columns.
For example data is:
ABCDEF1
Machine
4394264394294394434399834399842
Model
TD860TD400TD860TD620TD6203
Pgm
OPTABCOPTEP2EP24
Start
5/31/119/1/115/1/096/15/092/1/085
End
2/28/158/31/125/31/114/30/108/31/09
I need to sort it first by Pgm, within Pgm by Model, and within Model by Machine. I do not need to sort on Start or End
The results should look like:
ABCDEF1
Machine
4394294399834399844394264394432
Model
TD400TD620TD700TD860TD8603
Pgm
ABCEP2EP2OPTOPT4
Start
9/1/116/15/092/1/085/31/115/1/095
End
8/31/124/30/108/31/092/28/155/31/11
After selecting the data to be sorted (columns B,C,D,E,F), I tried using "Sort Left to Right" under DATA-SORT-OPTIONS but it doesn't seem to work.
View 3 Replies
View Related