Sort Ranges Across Multiple Sheets

Jan 24, 2010

Sub DynaSort()
Dim wsSheet As Worksheet
iRow = ActiveSheet.Columns("A").End(xlDown).Row
For Each wsSheet In Worksheets
Select Case wsSheet.CodeName
Case "Sheet2", "Sheet3", "Sheet4"
wsSheet.sort.SortFields.Clear
Range("A3:I" & iRow).Select
wsSheet.sort.SortFields.Add Key:=Range("F2:F" & iRow) _
, SortOn:=xlSortOnValues, order:=xlAscending, DataOption:=xlSortNormal
wsSheet.sort.SortFields.Add Key:=Range _
("H2:H" & iRow), SortOn:=xlSortOnValues, order:=xlDescending, DataOption:= _ ...................

The problem that I has is that I cannot put focus on a cell after the sort. Xl keeps the columns selected and then when I'm trying to put in the next data Excel selects all the rows in Sheet1 also. I know how to get rid of it and continue, the users on the other hand are not that experienced with excel. fun thing, even thou the, Range.value is inside the IF it putt "pucko" in sheet1. I have a code that copies the data and then put some several functions in each sheet, after that I call the sort routine.

View 8 Replies


ADVERTISEMENT

Adapt A Macro To Sort Multiple Ranges?

Jun 18, 2013

I'm trying to adapt this macro (without success) to sort a number of ranges rather than just one:

Dim rng As Range: Set rng = Range("B11:F45")
With rng
.Sort Key1:=Range("C11"), Order1:=xlAscending, Header:=xlGuess
End With
Set rng = Nothing
End Sub

I want to ADD some further parameters

to set Rng H11:L45 and Sort Column I11:I45
to set Rng N11:R45 and Sort Column O11:045

There's many more but I've tried to add in ranges but it won't work.

View 1 Replies View Related

Sort: Multiple Varying Size Ranges

Dec 4, 2006


name data1 data2 total
chris a b 100
a a 100
a a 100
steve b b 90
b a 90
b a 91
jane b a 89
a a 90
a a 92

its hard to line things up in here..... anyway... each name has two more lines of data associated with it. i want to take the 4th column last line for each and sort from greatest to smallest and rearrange all the data but keeping all three lines associated with each person together. one added complication. the number of ppl in this will vary although i can do a count of every three lines and tell exactly how many there will be. so for this purpose we can just keep it at three.

in this case, all three lines associated with jane should be moved up above the three lines of steve but stay below the three lines of chris. and the three lines for each person stay in the same order they are now

View 9 Replies View Related

Sort Data Ranges Across Multiple Worksheets

May 2, 2008

I have been asked to create an attendance worksheet where employee names and data are entered on a "main" worksheet and hours are entered on monthly worksheets. The names on the monthly worksheets are referenced from the main worksheet. Therefore, if I add a name and do a sort, the names on all pages will move, but the data will not. I imagine I will need an ID column to help sort. How do I make a macro to do the sort?

View 2 Replies View Related

Non Consecutive Rows Sort Data With Multiple Ranges

Feb 23, 2010

Once again, I'm seeking some further assistance to an issue that I have yet to resolve.

I have several rows of data which I'd like to be able to sort by the info in column "A".

The data rows are not all consecutive. The range for which the data resides are:

Range("A25:A73,A85:A105,A145:A193"), When I sort I want my data to stay within these limits/ranges.

View 8 Replies View Related

Copy Multiple Ranges From Multiple Sheets And Paste In Order Via VBA

Apr 21, 2013

I've got several worksheets that all have the exact same layout that a user will enter unique information in to each worksheet. Then I've got a final worksheet that I want to have a button that the user can click and when they do, it will look to each worksheet and do the exact same process for each worksheet as follows:

It first looks to see if the worksheet is visible. If it is, I want it to copy the range A5 to K5 down until it gets to the last non-blank cell in column C. The first non blank cell that will be referenced will be C7. Then I want it to paste this information into the range A5:K5 on the final sheet named Sheet8 with the same values and keep cell formatting such as width and height, font. If the worksheet is not visible, it skips the sheet.

I want it to do this for each visible worksheet, placing the next visible worksheet info under the previous visible worksheet info. My current code as shown doesn't do that. It requires that something be inSheet8 A6 before it will even paste, then it pastes the info from A5:K5 but it doesn't do just the values nor does it keep the formatting. What I mean about not doing just the values is some of the info that needs to be copied comes from a drop down they can choose from and it copies the actual drop down menu. Also, it seems to copy all of the ranges from each sheet and paste it into just A5:K5 on Sheet8 and overwrites each other instead of pasting Sheet2 just below the information from Sheet1. So the only information shown after the entire process is completed is the information from the last visible sheet.

If Worksheets("Sheet1").Visible = True Then
Sheets("Sheet1").Range(Sheets("Sheet1").Range("A5:K5"),
Sheets("Sheet1").Range("C7").End(xlDown)).Copy
Sheets("Sheet8").Range("A5").End(xlDown)
End If

[Code]...

View 4 Replies View Related

Print Multiple Ranges From Multiple Sheets Userform

Jun 16, 2007

I inherited a spreadsheet that had an userform where the user checked off which 'pages' he wanted to print. The Ok button routine used if statements to run a routine for each 'page.' Here's an example of the original code for one page:

Sub Button2_Click()
Sheet7.Activate
Run "HorizontalPrintStuff" 'generic landscape pagesetup
With ActiveSheet.PageSetup 'specific pageset settings
.RightFooter = " Construction Assumptions"
.PrintArea = "CONSTRUCTION" 'the named range to print
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1 'this changes depending upon the page selected
End With
ActiveSheet.PrintOut
End Sub

The problem was it printed each page as a separate print job; and if you print to adobe, you get serveral files, not one file. That and it took a long time to run.

So I tried a different tack. If the checkboxes has true, then the printarea is set to that named range. If there were more than one named range on a sheet to be printed, I consolidated them. I did this with a bunch of if statements - very cumbersome.

Sheet3.Activate
'Sheet3.ResetAllPageBreaks 'disabled due to errors
Run "HorizontalPrintStuff" 'generic landscape pagesetup
With ActiveSheet.PageSetup 'specific pageset settings
.PrintArea = "DEVBGTALL" 'the named range to print
.FitToPagesWide = 4 'this changes depending upon the
.FitToPagesTall = 1
End With

I haven't shown all the code cause it goes on for 12 sheets containing 16 different printareas.

My current muck ups are .....

1) it prints every printarea/named range on a given sheet (I took out all the if statements trying to debug everything.) Is there another conditional argument that allows for multiple 'trues'?

2) the pagebreaks in printarea/named ranges that are multiple pages (like a 48 month schedule) won't stay set. I've tried both VPageBreaks(3).Location:= and .VPageBreaks.Add Before:=

3) the Sheet1.select false argument is always adding a random sheet to the end of the print job. Don't know why.

I can do all this in a recorded macro, just not the selection userform. I've thought about copying to another sheet or hiding columns and rows then printing, but that seems just as cumbersome.

To recap, i want to print out, as one print job, multiple printareas from mulitple sheets, based upon checkbox selection on an userform.

View 6 Replies View Related

Track Changes On Multiple Selected Ranges On Multiple Sheets

Jul 6, 2007

I need to be able to track changes on selected ranges on multiple sheets, but Excel does not appear to be able to do this. It only appears to allow me to select multiple ranges on the same sheet.

is there a way to track changes on multiple selected ranges on multiple sheets

View 9 Replies View Related

Custom Sort Multiple Sheets?

Nov 23, 2011

I have found many macros for sorting multiple sheets by a single column in Excel, however, need macro for sorting multiple sheets by column "A", then column "B".

View 1 Replies View Related

Sort On Multiple Sheets In Workbook?

Nov 18, 2013

Trying to sort on multiple sheets in the workbook. The range that is to be sorted will vary on each sheet, so i would like to write the range as .end(xlDown).Row and then do the sort. So far, what I have written is giving me a type mismatch error

Code:
.Sort.SortFields.Add Key:=Range("B2:B" And Range("B2")).End(xlDown).Row, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

View 3 Replies View Related

Dynamic Sort Across Multiple Sheets

Dec 19, 2008

I'm trying to write a code to sort a variable-sized data range on several sheets. A sql query populates several sheets with data in N rows, where N varies based on query parameters).

I get a run-time error on the .sort command (method range of object global failed). i think this has to do with sorting by the same column on multiple sheets and haven't been able to debug it myself.

Sub sort()
Dim lastrow As Integer
Dim rows As Integer
Dim sheetarray As Variant
Dim colarray As Variant
Dim i As Integer

View 7 Replies View Related

VLookup To Work For Multiple Ranges On Different Sheets

Feb 23, 2012

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(ActiveCell, Sheet8.Range("C16:Y1000")) Is Nothing Then Exit Sub
Dim rw As Integer
Dim arw As Integer
rw = 16

[Code] .....

As you can see, my code is located in the sheet8 worksheet object. Now, I have a few questions about this. Because I am located in the sheet8 worksheet object does that mean my code can only work in sheet8, i.e., the following won't work because I am in a Sheet8 worksheet object?

Sheet10.Range("B12) = ..... ....... .....

This is not returning a value in Sheet10? My question is how do I make my code return a value in Sheet10?

View 6 Replies View Related

Clear Contents Of 2 Ranges On Multiple Sheets

Mar 29, 2012

I need to clear the the text in the same cell ranges on multiple worksheets. on a regular basis.

F7:K13
Q7:Q13

Is there a simple way to do this?

View 7 Replies View Related

Form Range From Ranges On Multiple Sheets

Jul 20, 2009

Is it possible to form a single Range object from ranges on multiple sheets. So for example, would it be possible to set a Range object equal to cells A1:D146 from Sheet 1 and A1:B49 from Sheet 2 and if so, what would be the syntax? For the first I have:
Sheets("SelectData").Range("A1:D146").SpecialCells(xlCellTypeVisible)
but I wouldn't know how to proceed from there.

View 9 Replies View Related

Macro: Print Ranges From Multiple Sheets

Dec 6, 2006

I am trying to write what I thought would be a simple macro to print out specific areas of my worksheets. I have shown the code below; the line causing the problem I have highlighted in RED. I am getting the following error message: "Select method of range class failed".

Reading other posts here. I think this may have something to do with the macro being assigned to a command button in one worksheet (AY114) and I am trying to get the macro to run on both the worksheet that the command button is in (AY114) as well as another worksheet (AY062).

Sub CommandButton1_Click()
Range("J2").Select
Sheets("AY114").Select
Range("A4:J53").Select
ActiveSheet.PageSetup.PrintArea = "$A$4:$J$53"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.SmallScroll Down:=45
Range("A56:M151").Select
ActiveSheet.PageSetup.PrintArea = "$A$56:$M$151"......................

View 4 Replies View Related

Macro Sort Rows In Multiple Sheets

Jan 31, 2014

Sorting.xlsx

I am trying to figure out how to make a macro that can sort some numbers from Largest to Smallest within a specific range on multiple sheets. The range is only within column D starting with cell D11: (until the data ends) on all the sheets in my workbook (the number of sheets may change with time) except for Sheets: "A", "B" and "C".

In other words I want the sort to work on all sheets except the first 3 sheets which are named Sheet A, Sheet B, and Sheet C.

I have attached a spreadsheet for an example of what I am saying.

View 5 Replies View Related

Excel 2010 :: VBA - Convert Selected Ranges In Multiple Sheets Into One PDF

Feb 10, 2014

I'm using Excel 2010 and would like to know if it's possible to convert selected ranges in multiple sheets into one PDF file? For example, I want to select range("A1:O10) in Sheet1 and range("A1:N25") in Sheet2, then convert both Excel sheets into PDF file with two pages.

View 2 Replies View Related

Named Ranges On Multiple Sheets With The Same Named Range & I Cant Figure Out How To Do This

Jun 2, 2006

I need to create a named range on multiple sheets with the same named range & i cant figure out how to do this. EG :- I want to create a named range called "_SubUnitRows" on sheet1 starting from "A1:A50" & other named range again called "_SubUnitRows" on Sheet2 starting from "A1:A25" ...

View 2 Replies View Related

Sort Data Into Ranges?

Mar 12, 2013

sort data into ranges like in the example below:

1,2,3,4,5,6,10,11,12,15,19,21,27,28,29,30 [Each value is in a cell vertically]
into
1 to 6
10 to 12
15
19
21
27
28 to 30

provide the vba code for this ?

View 1 Replies View Related

Sort Data With Dynamic Ranges

Jun 8, 2014

I currently have two tables in one worksheet showing the sales of different region.

The problem is, when I sort the data in the table (I can't used the named ranges as it should exclude the first row which is the header), is there a way I can make it dynamic too??

**Attached, please find the example spreadsheet, I have only written the code for the first table.

View 3 Replies View Related

Automatically Sort Ranges On Calculation

Feb 5, 2008

I've created this fantasy football programe to calculate all the scores from all matches in this years European Championships.

Basically everybody ranks each team from 1 to 16, giving 16 points to the country you think will win the european championship, 15 points to the runner up, and so on down to the country, you think is the weakest on just 1 point.

Everytime I try and change one of the values in the 'Results' tab I get an "Compile Error/Syntax Error".

What this macro should do is sort all the data in the "League Table" tab into a highscore table list.

Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Range("b1"). CurrentRegion.Sort _
Key1:=Range("h2"), Order1:=xldescending,
Key2:=Range("c2"), Order2:=xldescending,
key3:=Range("e2"), order3:=x1descending,
Header:=xlYes
Application.EnableEvents = True
End Sub

View 3 Replies View Related

Custom Sort Non-Contiguous Ranges

May 21, 2008

can anyone modify below macro to sort this data:

before sort:
---A-B-C--D-E-F--G-H-I
1-99-5-6-99-1-2-99-3-4
2-99-6-5-99-2-1-99-4-3
3-99-7-8-99-5-6-99-8-9
4-99-8-7-99-6-5-99-9-8
etc

after sort:
---A-B-C--D-E-F--G-H-I
1-99-5-6-99-1-2-99-3-4
2-99-5-6-99-1-2-99-3-4
3-99-7-8-99-5-6-99-8-9
4-99-7-8-99-5-6-99-8-9
etc

Sub SortNoncontiguousRanges()
Dim rRange As Range
Dim lArea As Long
'10 rows in columns B and C
'10 rows in columns E and F
'10 rows in columns H and I
Set rRange = Range("B1:C10,E1:F10,H1:I10")

With rRange
For lArea = 1 To .Areas.Count
With .Areas(lArea)
.Sort Key1:=.Cells(1, 1), _
Order1:=xlAscending, Header:=xlNo, Orientation:=xlLeftToRight
End With
Next lArea
End With
End Sub

View 9 Replies View Related

Fill/Populate ListBox From 2 Ranges, Sort & Remove Blanks

May 18, 2008

I need a listbox or combobox in an excel form whos list is created from 2 ranges. for example first name is range a2:a500 second name is rangne b2:b500. the list box should list both coloums in a single list and return the row number. better still if it does not list blank ranges. i have never used a list or combo box before so please explain in terms a simplton can undrstand

View 7 Replies View Related

Ranges Within Sheets

Apr 27, 2007

I'm trying to operate on sheets using an array. It is not placing the value found with Countif() into the correct cell in J5.

Dim lCount As Long
Dim mysheet As Worksheet
For Each mysheet In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
With mysheet
For lCount = 1 To WorksheetFunction.CountIf(Range("F4:F150"), "1")
Next lCount
Range("J5").Select
ActiveCell.FormulaR1C1 = lCount - 1
End With
Next

View 2 Replies View Related

Create Sheets From Ranges

Oct 16, 2009

I have this file, I would like to create a sheet for each different supplier code (column D), and each sheet named with the supplier code.

View 3 Replies View Related

Union Ranges On Two Different Sheets

Mar 3, 2008

I'm trying to union two different ranges that exist on two different sheets and then copy the unique values into a third range with just the unique values. I was going to then use the unique range as my rowsource in a listbox. This is the code I was working with so far but i'm getting a compile error (method range of object failure).

Private Sub UserForm_Initialize()
Dim range4 As Range
Dim range3 As Range
Dim range2 As Range
Dim range1 As Range
Set range1 = Worksheets(1).Range("MyRange")
Set range2 = Worksheets(2).Range("MyRange2")
Application.Union(Range("range1"), Range("range2")).Select
Selection = range3
range3.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=range4, Unique:=True
Me.lstone.RowSource = range4
End Sub

View 9 Replies View Related

Sum Different Ranges Across Sheets/Worksheets

May 26, 2008

I have three sheets: On sheet 1, I have a list of products ( Down ) with Bought and sold info by time period ( Across ). On sheet 2, I have the same list of products from sheet 1 ( May not be in the same order ) with " Attributes " associated to them ( e.g. male, female etc ). On Sheet 3: I would like to add the Bought and sold info by time period on sheet 1 by attribute as per sheet 2

View 2 Replies View Related

Macro To Compare Two Ranges In Two Different Sheets

Apr 17, 2014

I am relatively new to VBA macros. I am having two sheets, in one sheet I have a non-contiguous 20 rows range and in the other sheet I have a 20 row contiguous range. I need a macro which will compare data between the two ranges(one to one compare) meaning 1st row of the first range should compare with 1st row of the second range and if it matches then it should populate the adjacent column in the second sheet with true or false accordingly.

View 2 Replies View Related

Copying Sheets Containing Named Ranges With VBA

Apr 9, 2014

This should be a fairly simple question, I've already got the code for copying sorted, I'm just curious about several of the named ranges within the sheet and what happens to them when I copy it all over.

I'm working from a spreadsheet made by my predecessor and they've got a template sheet with numerous named rages all scoped to the workbook, on the new template I've created, it has lots of ranges scoped to the sheet itself. The new template works just fine as it is but I just want to try and make sure that when I change over the templates it will continue to work fine and the current template's named ranges are going, so far I have actually copied everything and are running tests, but you can't test for everything, so if the named ranges on the new template being only scoped to the sheet will affect it at all?

View 2 Replies View Related

Mirror Two Ranges Of Data On Different Sheets

Jun 7, 2007

Is there a way to mirror two ranges of data on different sheets - i.e. if I update one sheet, it updates on the second, without using formulas, macros.

View 3 Replies View Related







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