Sort Range

Mar 6, 2009

I would like it to sort for me and I can't seem to get that going. The sort order should be by C ascending, then by B ascending and by d ascending. I am adding this to a macro that is already running. The beginning of the macro copies the sheet and renames it based on myinput.

HTML
Dim LstRow As Long
Dim Rng As Range
LstRow = Cells(Rows.Count, "A").End(xlUp).Row - 1
Set Rng = Range("A2:m" & LstRow)
Rng.Select

View 3 Replies


ADVERTISEMENT

Sort / Filter Rows: Sort A Range Of Row

Nov 26, 2008

I would like to ask if it is possible to sort a range of row? What I mean is, if I sort like Row 1, the entire block of row 1 will move as well? Like if i have column A to F, then row 1 of column A to F will move together at the same time.

View 3 Replies View Related

Function To Sort A Range By The Values In A Specific Column And Return The Range

Mar 25, 2009

I was just recently forced to create my first UDF and after how well it worked I now am very interested in learning more. I am trying to create a function to sort a range by the values in a specific column and return the range. I know this should be really simple but for some reason my code dies whenever it gets to my inner-most loop. I need to use this in a larger function but for now this is my only question. I did find that Excel 2007 has built in Functions for this but my company still uses 2003.

My
Public Function SortRange(rngToSort As Range, valCol As Integer)
Dim Swapper As Variant
Dim i As Integer, _
j As Integer, _
k As Integer

For i = 1 To rngToSort.Rows.Count
For j = 1 To rngToSort.Rows.Count - i
If rngToSort(j + 1, valCol) < rngToSort(j, valCol) Then
For k = 1 To rngToSort.Columns.Count
Swapper = rngToSort(j, k)
rngToSort(j, k) = rngToSort(j + 1, k)
rngToSort(j + 1, k) = Swapper
Next k
End If
Next j
Next i
SortRange = rngToSort
End Function

View 9 Replies View Related

Dynamic Named Range Sort Including Cells Outside Defined Range

Apr 3, 2008

Im sorting a dynamic range as mentioned in this Sorting a Named Range. My range is called drWarningTypes and is defined as:

=OFFSET(DataSource!$A$2,0,0, COUNTA(DataSource!$A:$A)-1,1)

When there is only one cell in the range, then running the following sort function includes A1 also in the search (and also adjoining columns).....

View 9 Replies View Related

Range Name And Sort

Jan 18, 2007

i have a large sheet that was set up starting at cell A3

A3:P19 is one week of data
A20:P38 is the next week of data

Each week contains 17 rows.

What i am trying to get is something that will Name each week, starting with the first week of data A3:P19 "1"
the next 17 rows, a to p is named 2
the next 17 rows, named 3

etc etc.

Then i want to sort by range, in decending order. ( I hope this is possible)
is this doable? it will save alot of time if it is.

View 9 Replies View Related

Range Sort Not Working?

Jun 27, 2014

I'm highlighting a range and then sorting column F from Largest to Smallest. The macro doesn't sort it at all. Added my code tags.

View 1 Replies View Related

Range Array Sort

Oct 20, 2009

I am trying sort a bunch of different ranges. So I am trying to use the same sort code but run an array of ranges through. This code is for only two ranges
CA3:CD200 and CF3:CI200. I want to pass the ranges as variables through the sort code but I cannot get it to work.

View 4 Replies View Related

Add Textbox Then Sort Range

Nov 20, 2009

I have the following code for a button on a form which is supposed to add the text entered into textbox1 of the form to the bottom of a range of cells and then sort that range of cells in 'A-Z'.

View 5 Replies View Related

VBA Macro To Sort Range?

Sep 12, 2012

I am trying to write a macro to sort a range of data by another column. Here's the code that I already have :-

Code:
Public Sub sort_data(sort_range As Range, key_range As Range)
' MsgBox sort_range.Address
' MsgBox key_range.Address
sort_range.Sort Key1:=key_range, Order1:=xlAscending, Header:=xlYes
End Sub

However I get a run time error 1004 stating that the sort reference is not valid.

View 6 Replies View Related

Sort A Range Of Cells

Jun 18, 2007

I have a spreadsheet that I am tryng to sort. I am sorting a range of cells. I get my list sorted how I want but then I want to go one step further which is why I am seeking assistance. After my initial sort I want to select just a few specific cells and resort only them.

I am identifying the cells I want to sort by placing "zzzSort" in column V (V267 to V516) ("zzzSort" is placed in the desired cells automatically).

Is there a VBA code that I can place after my original sort code that would select the rows with "zzzSort" in Column V and then run only those ones through anouther sort.

View 9 Replies View Related

Auto Sort Set Range

Mar 11, 2009

I know that I could just click sort, decending, "points" etc but I figure there must be a way of it auto updating.....

Please see the attached file - I have attempted doing it with Ranking Formula but forgot that it would just give me error messages when two have the same points so I got rid of that.

Have tried doing it with other formula found on this website and others, however I appear to be stuck. I might be doing it wrong but as I'm not manually putting in the "points", they are being worked out with =( SUMPRODUCT((H4:H16={"W","D","L"})*({3,1,0}))+58) for example, it does not move their position.

What I would like it to do:

1. People select from drop down list whether they think the team will W, D, L
2. The Table to the right should automatically change the points dependant on the result
3. The Teams position should change automatically in line with their new points total.

View 9 Replies View Related

Sort Changing Range

Aug 24, 2007

I am using the following:

Sub Sort_Labour_Dates()
With Range("A10:Z18")
.Sort Key1:=Range("A10:A18"), Order1:=xlAscending, Header:=xlNo
End With
End Sub

This works perfect but I will be inserting rows between A10 and A18. So when it comes to sorting out the range with more rows it will not sort all the data.

But I do not want to be sorting the whole column as I have seperate data below hence why I will be inserting rows between A10 and A18.

View 9 Replies View Related

Sort Range On Worksheet_Deactivate

Jan 23, 2008

I have it a workbook with 7 worksheets. 6 out of the seven have unique data sets and the seventh one totals them all up. Now I have sorting macros in each of the 6 unique worksheets but unless they are returned to the original sort order (ie: by persons last name: before changing to the next worksheet the totaling will be incorrect as the data is not sorted accross the entire workbook. The reason I sort while inside the worksheet is plainly for printing purposes, then I want to reset the sorting to Last Name column. Anyway I tried to add a macro to sort the data on worksheet_deactivate but instead of sorting the data on the sheet that the user is leaving it does the sorting on the sheet they click to goto. Any ideas? This is similar to another post Sheet Event Code Not Firing:

I've tried putting this code in each sheet individually and the ThisWorkbook / Workbook section as a Private Sub with no avail and the macro I'm trying to run is located in Module1 and is named "data_b"

View 9 Replies View Related

Macro To Sort Dynamic Range?

Jun 6, 2013

I have a Ranking tab that has the persons name, weeks, months that subtotal into 2 columns, MTD and YTD. I have set up with 2 Macros to sort based on two columns based on their selection of MTD or YTD.

What I did not take into consideration is if a person was added at the bottom of the list.

Is there a way to modify this to include rows that may be added?

VB:
[SIZE=4]CODE HERE[/SIZE]
VB:
[B]Macro1
[/B]Sub SortYTD()

[Code].....

View 8 Replies View Related

Sort And Obtain The Lowest Value In A Range

May 1, 2014

Excelforum.jpg

What I want to do is in column 5 row 1, I want it to show a value only if all 4 columns, row 1 are filled in. For example in the picture I want to show a blank in the first 8 rows but to start showing a value on the rest of the rows, in this example IPE 240 to be the first value. When it shows this value from this row I want it to obtain the value with the highest percentege inside. For example in this picture the correct value first value to be shown in column 5 will be IPE (84%)

Ive done this code so far: =IF(AND(B256<>"",D256<>"",F256<>"",H256<>""),Here I want it to show the value on the row that has the highest percentege,"")

View 14 Replies View Related

How To Sort Range By Cell Color

Apr 9, 2014

I have a spreadsheet we use as a "Stock Location guide" and the critical colums are as follows, Column A = Location, Column B = Date and Column F = Material Description. The following code is what we have been using to sort the guide in order of F, B and then A :

[Code] ..........

What we want to do is swap "A" and "B" so "A" is sorted before "B" and also to change the way"A" is sorted. Certain cells in "A" are yellow and I want to be able to sort by Cell color with yellow on top.

View 10 Replies View Related

Sort Alphabetic With VBA On Range Till Last Row?

May 13, 2014

I am running a formatting excel, and I will also need to select from cell P30 till last row, then sort alphabetically by moving the other rows data too.

View 3 Replies View Related

Data Sort For Variable Range

Apr 6, 2009

I have a recorded macro to sort Data with 3 sort fields but has a Fixed range. The Data will increase each week so I need to modify to account for growth.

View 2 Replies View Related

Sort Named Range Within Macro

Dec 8, 2011

I have a named range that is being updated via a macro. After the update, I want the list to be sorted. The named range is "Projects". This name is not a variable...it is a named range within Excel itself.

Any code to sort this at the end of my existing macro.

View 1 Replies View Related

Sort Dynamic Data Range

Apr 8, 2014

How might the code below be changed to handle any number of rows? Right now it's set (from a recorded macro) to go down through row 237, but I need it to sort anything from just a few to maybe a thousand.

Cells.Select
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("C2:C237"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveSheet.Sort.SortFields.Add Key:=Range("B2:B237"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveSheet.Sort.SortFields.Add Key:=Range("K2:K237"), _

[code]...

View 5 Replies View Related

Variable Named Range Sort VBA

Oct 8, 2009

In column B, I have a series of named ranges. The named ranges can vary in order. If I wish to reference a range from a named range say Range("I") to the next unkown named range,

View 9 Replies View Related

Sort Range Via VBA Macro Code

Jul 16, 2009

I recorded this macro - which was a simple copy and paste and then sort the results, however it works in excel 2007 and not in 2003. Even tried to record the same in excel 2003 and it still does not work. It seems to fail at the sorting stage

Sub sortprices()
Sheets("Rates").Select
Range("B229:C241").Select
Selection.Copy
Sheets("Results").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Results").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Results").Sort.SortFields.Add Key:=Range("D4:D16") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Results").Sort
.SetRange Range("C4:D16")
. Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("C4").Select
End Sub

View 4 Replies View Related

Sort Set Range Across Multiple Worksheets

Oct 9, 2009

I would like to use a macro to sort multiple worksheets simultaneously. I need to sort on last name (column A) then first name (column B) and my data does not start until the 8th row (A8:AF8). The data range should be the same for all worksheets that I need to sort. I found the code below here on ozgrid (Dynamic Sort Across Multiple Sheets) but I'm not sure if its appropriate or the best way to customize it so that the 1. Can sort on two criteria

2. Is specified to nonblank cells in a specific range, A8:AF8 and below

Sub DynaSort()
Dim wsSheet As Worksheet

For Each wsSheet In Worksheets
Select Case wsSheet.CodeName
Case "Sheet1", "Sheet2", "Sheet3", "Sheet4"
With wsSheet
.UsedRange.Sort Key1:=. Range("B14"), Order1:=xlAscending, Header:=xlYes
End With
Case Else
'Nothing
End Select
Next wsSheet
End Sub

View 9 Replies View Related

Macro To Sort Expanding Range

Aug 13, 2007

I have an Excel sheet that lists all of my dvd collection.

Its very easy to use, all I need to do is type the movies I have then click a sort button.

The everything goes into alphabetical order.

The problem I'm having is it only goes to 999 I have tried to extend it to 3000.

I can't seem to find the formula to allow me to extend the perimeter past 999.

View 8 Replies View Related

Sort Range By Column Containing Blanks

Aug 14, 2007

I have some trouble to find a solution to sort blocks of data, the blocks have multiple headers and i would like to sort by the user column C.

I have attached a sample to easier understand my ramblings.

View 4 Replies View Related

Sort Range On Non Active Sheet

Dec 22, 2007

I'm trying to sort data on sheet1 and sheet2. I'm running all macros from sheet one and I need it to stay active all of the time. I'm using the following code to sort sheet2. When I sort the column on sheet2 with the code, I can not get back to sheet one without an error.

Worksheets("Sheet2").Activate
Columns("a:a").Select
Selection.sort Key1:= Range("a1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

I've tried

Worksheets("Sheet1").Activate
Columns("a:a").Select..............

View 2 Replies View Related

Sort Every Nth Column Range Separately

Apr 24, 2008

I have a question regarding automating excel sorting in Excel 2007. Here's what I have, I have a sheet that I need to sort on a weekly basis as the data is always being updated. Here is what i am basically doing with sheet and I am using a MACRO RECORDER to automate it.

1) I select column2 ~ column 7 (B:G)

2) I sort with the following order.

- column 3 (column C) ascending order, then

- column 4 (column d) ascending order, then

- column 6 (column f) ascending order, then

- column 2 (column b) DESCENDING order.

everything from this point on, it's repeatitive. I select..............

View 4 Replies View Related

Sort Range Data Blocks

May 9, 2008

I have a list of data (as shown below under Input), which I would like to sort them according to their block number (as shown below under Output). The hurdle is the sorting should be able to cater for missing fields. Also, note that the sector can be recurring, that is "P,P,Q,Q", and then follow by "P,P,Q,Q" again.

INPUT
Block No.SectorData
11P19
22P
33P39
41P18
52P21
63P38
75P22
85P24..............................

View 2 Replies View Related

Sort Range Of Cells On Each Worksheet

Jun 13, 2008

I have been trying to sort the cells in a worksheet, but am unable to properly select the range of cells I need

For Each ws In Worksheets
If ws.Name <> "MySheet" Then Goto nxt
If ws.Name = "MySheet" Then Worksheets("MySheet").Activate
Range("A1:F" & totval).Select
Selection.Sort Key1:=Range("F1"), Order1:=xlDescending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
nxt:
Next ws

the code mentioned above throws an error when it gets to the range.select line. I cannot simply say usedrange.select.

It keeps throwing error 1004.

Please ignore the "& totval" in above code. That was my attempt at specifying the last row number, which i specified in the totval variable

I dont know how exactly to specify the range of cells containing data in the activated worksheet above, and then select them for sorting.

View 4 Replies View Related

Sort And Filter Range With Protected Cells

Nov 9, 2008

Is there any way to allow autofiltering and sorting even with locked cells within the range to be sorted? I've conditionally locked some cells based on user input, and at the end of my vb code I have allowsorting and allowfiltering. But I want to sort cells that are locked even after that. Does anyone know if that's even possible with VB?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved