sorting across sheets in excel - sorting

I don't know if this is possible or not.
I have a workbook that has two sheets, "input" and "output"
user1 fills in the "input sheet"
Column A = name
Column B = Age
Column C = Location
Column D = Hight
..
..
Then on the "output" sheet Column A is set to copy the value from Column A on the "input" sheet and User2 fills in more details using the values that user1 has entered
Column B = eye colour
Column C = hair colour
Column D = number of fingers
..
..
So I hope you get the idea, User1 enters some details, and then User2 does some work with that and enters more details in the "output sheet. With Column A being the "index" value that links the two together.
My issue is that if User2 enters there details, and then goes back to the "input" sheet and preforms a sort, the values in the "output" sheet will no longer match, as while Column A will have changes to reflect the sort operation the rest will stay the same.
Is it possible to link rows between sheets, or to create a sort code that will run across both sheets and keep them consistence.
This does not have to work for ad-hoc searches that the user tries, I just want to put a button on the "input" sheet, for example to "sort by name", "sort by Location" etc
Regards
Aaron

If you're ok with having pre-set sorts, one solution is to mirror both values from sheet A and sheet B to sheet C, and then just sort that, and re-populate the values in sheet A and B with the new, sorted, results.
I.e.
Sheet1 | Sheet 2 | Sheet 3 (Hidden and named)
| |
Name Age etc, | Eye Colour Hair colour etc. | =Sheet1!A1 ... =Sheet2!A1
Then your sort button would call a sub something like:
Dim rngSortRange As Range, rngStartCell As Range, rngEndCell As Range
Set rngStartCell = Worksheets("Sheet_3_Name_Goes_Here").Range("A1")
Set rngEndCell = Worksheets("Sheet_3_Name_Goes_Here").Range( _
rngStartCell.End(xlToRight).Column, _
rngStartCell.End(xlDown).Row)
Set rngSortRange = Worksheets("Sheet_3_Name_Goes_Here").Range(rngStartCell, rngEndCell)
rngSortRange.Sort Key1:=<Column Number Here>, Order1:=xlAscending, Header:=xlYes
rngSortRange.Range(rngStartCell, _
Worksheets("Sheet_3_Name_Goes_Here").Range( _
Worksheets("Sheet 1").Range("A1").End(xlToRight).Column, _
rngEndCell.Row _
) _
).Copy
Worksheets("Sheet 1").Paste
rngSortRange.Range(Worksheets("Sheet_3_Name_Goes_Here").Range(
rngStartCell.Column + Worksheets("Sheet 1").Range("A1").End(xlToRight).Column, _
rngStartCell.Row _
), _
rngEndCell _
).Copy
Worksheets("Sheet 2").Paste
That might need some work (e.g. you might need to reset sheet3 afterwards, you might need to pastevalues rather than just paste, else you'll end up pasting self-referencing formulas), but the basic idea should work.

Related

Google Sheets - How to Combine Filter Function with Filter View

I've been working on a spreadsheet with over 100 rows, and found a hacky way to incorporate a "hide" checkbox that will hide any row where column C matches a specific value (building type), specified beside the box. To do this, I first created a function like this: =FILTER(Data!A1, OR(Data!$C1<>$O$2, $P$2)) and dragged that across every row and column in a seperate sheet. This reads as, "Display current cell if the corresponding column C in that row in Data does not match the building type, or if the the checkbox is checked. This way, the whole row is hidden when the building type matches, and the box is unchecked. A1 adjusted to each row individually, $C1 referenced the building's type, $O$2 referenced the targeted type to potentially hide, and $P$2 was the checkbox.
Problem #1: This created a lot of formulas in hundreds of cells, and when the building type was not found, it displayed #N/A across the entire row. A Filter View was able to hide these values, but it was inconvenient to have to reset the values every time I wanted to hide or unhide another building type.
My Attempt to Fix: I used a filter function once again to recreate the entire sheet from one cell, hiding the appropriate rows, using this: =FILTER(Data!A2:J191, ARRAYFORMULA((Data!$C2:C191<>$O$2)+(Data!D2:D191*$P$2)) This is the hacky part. I multiplied the checkbox's "true" by an array arbitrary positive numerical values in the D column to "OR" it with each building type value to achieve the same goal as before, but for EVERY cell.
Problem #2 arose: When I get my beautiful sheet, I can not sort it via a filter view, or it will throw an error and display nothing. I'm resorting to sorting the original tab, but intend to have it be ignored entirely. So how do I combine these two, Filter View, and Filter Function, to create a nice spreadsheet where I can SORT AND HIDE rows?
Bonus Problem #3: To add more buttons, my formula is this: =FILTER(Data!A1:J191, ARRAYFORMULA((Data!$C1:C191<>$O$2)+(Data!D2:D192*$P$2)), ARRAYFORMULA((Data!$C1:C191<>$O$3)+(Data!D2:D192*$P$3)), ARRAYFORMULA((Data!$C1:C191<>$O$4)+(Data!D2:D192*$P$4)), ARRAYFORMULA((Data!$C1:C191<>$O$5)+(Data!D2:D192*$P$5)), ARRAYFORMULA((Data!$C1:C191<>$O$6)+(Data!D2:D192*$P$6)), ARRAYFORMULA((Data!$C1:C191<>$O$7)+(Data!D2:D192*$P$7)), ARRAYFORMULA((Data!$C1:C191<>$O$8)+(Data!D2:D192*$P$8)), ARRAYFORMULA((Data!$C1:C191<>$O$9)+(Data!D2:D192*$P$9))) This is ugly, and very slow to load. Is there a way to create a function range to handle the same checks on multiple rows, and crunch it into a single formula?
Here is another monstrosity (this one has less repetition) for you:
=QUERY(
{IGNORE!A2:J, IGNORE!P2:P},
"SELECT * "
& "WHERE Col3 is not null "
& IF(COUNTIF(P2:P9, False) = 0, "", "AND NOT Col3 MATCHES '^" & JOIN("$|^", IFNA(FILTER(O2:O9, P2:P9 = False))) & "$' ")
& IF(COUNTIF(A2:K2, ">0") = 0, "", "ORDER BY Col" & JOIN(", Col", IFNA(FILTER(COLUMN(A2:K2) & IF(COLUMN(A2:K2) = 1, "", " DESC"), A2:K2)))),
0
)
Your checkboxes should remain. The second row can have just True/False values, no need for column number (a simple change will be needed COUNTIF(A2:K2, ">0") -> COUNTIF(A2:K2, True)). Also consequent sort works now (but only in the actual order of columns: if checked 1, 3, 4 then it will be sorted first by 1, then by 2, then by 4). You could place another config table on the right about sorting, where you would select all the columns you wish to sort by, their mutual order, and desc/asc for them.
Edit: added IFNA so FILTER won't return an error, changed multiple ANDS to MATCHES and simple regexes.

Move entire row when sorting column (Google Apps Script)

I have a list of names in Column B, and a bunch of data (ID number, bank account details, etc.) in columns C:AK that corresponds/belongs to the name in column B.
I want to sort column B alphabetically, but the entire rows data must move with the name when sorted.
E.g. Lets say Ted is in B2 and Amy is in B3. When I do myrange.sort(2), Ted will now move to B3, but C2:AK2 must also now become C3:AK3. Otherwise Amy's personal details will now show up in the same row as Ted.
Does that make sense?
Example code:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Summary');
var curRange = sheet.getRange("B2:B6");
curRange.sort(2);
Your range only contains a single column so naturally, calling the 'sort()' method ignores all other columns in the sheet. You should select the entire data range and then sort by the selected column
var sortRange = sheet.getRange("B2:AK");
sortRange.sort({column:2, ascending: true});

Filter in OpenOffice Calc

Scenario:
I have a spreadsheet with info from a giveaway campaign in which I get paid per new Twitter follow my client receives through my campaign. Unfortunately the application I use does not track new followers vs existing ones because they offer an entry for new and existing followers for the "Follow on Twitter for 1 Entry". Because I also offer other means to gain entries I need to export the data and filter the results to show only those who've gained an entry on the Twitter Follow and then filter out those who are new vs existing by means of a separate application.
Problem:
There should be a separate column for each data type; name,email,action, etc. The action column is where I would expect to find the "Follow On Twitter" but the file is very disorganized and the action can be found in many different columns. Therefore I need a way to show only the rows in which there is a field with "Follow on Twitter". I am at a loss to try and figure out how to do this.
The following macro will search for "Follow On Twitter" in each cell. For each row, if a match is found, the row will be shown, else it will be hidden. You will have to adjust the macro to match your sheet's total number of rows/columns.
Sub Dummy()
GlobalScope.BasicLibraries.LoadLibrary("Tools")
Dim ActiveSheet As Object
ActiveSheet = ThisComponent.CurrentController.ActiveSheet
Dim r,c As Integer
For r = 0 To 25
Dim found As Boolean
found = False
For c = 0 to 10
Dim cell As Object
cell = ActiveSheet.getCellByPosition(c, r)
If cell.String = "Follow On Twitter" Then
found = True
Exit For
End If
Next c
Dim row As Object
row = ActiveSheet.getRows.getByIndex(r)
row.IsVisible = found
Next r
MsgBox "Done"
End Sub

Filtering a validation list based on columns within a named range

I am looking for a way to filter a list validation in Excel based on a multi-column named range.
I have a list of product releases on one sheet, contained in a named range that has the columns: Name, Type, Status. On another sheet, I want the user to be able to select from a validation list containing 'Name' only.
Question 3741060 here covers how to make the validation list only contain the 'Name' column. However I also need to filter so that the user cannot select a release with the status 'Completed'. [The status column only allows 'Planned', 'Allocated' or 'Completed'.]
Ideally I would also like to dynamically show only 'Planned' OR 'Allocated' releases based on yet another validation - but I think if I can get the list filtered at all I should be able to do the rest.
BTW - I am forced to use Excel 2003 for this, although I don't believe would be a major factor.
I use
an extra range LOV (for List of Values) in a hidden sheet that I fill with the current criteria the user can choose from (in my case this varies from line to line as he/she fills the sheet)
all cells in the main sheet are validated against this range LOV
a Selection_Change() trigger loads the LOV after each cursor move from the original range of possible choices
This is how I re-generate my LOV (in essence the user has already selected a country code in another cell passed here in string CtyCd, and the sheet now is prepered to offer a selection of possible choices of something called GINI for only this country ... so maybe similar to your demand)
Sub LoadL2LOV(CtyCd As String, LOVL2 As Range)
'
' CtyCd is a selection criterium for the original list in range GINI
' LOVL2 is the target range containing the current list of values
' all cells in sheet have a validation against range LOV defined
'
Dim GINI As Range, Idx As Long, Jdx As Long, LName As Name, Adr As String
' clear current PoP_L2
Set LName = ActiveWorkbook.Names(LOVL2.Name.Name)
Set GINI = Worksheets("GINI Availability").Range("GINI")
LOVL2.ClearContents
' set new LOV for PoP_L2
If CtyCd <> "" Then
Idx = 2
Jdx = 1
' find 1st occurence of CtyCd in GINI
Do While GINI(Idx, 4) <> CtyCd And GINI(Idx, 4) <> ""
Idx = Idx + 1
Loop
' GINI is sorted, just read until the end of selected CtyCd
Do While GINI(Idx, 4) = CtyCd
LOVL2(Jdx, 1) = GINI(Idx, 1) & "-" & GINI(Idx, 2) & "-" & GINI(Idx, 3)
Idx = Idx + 1
Jdx = Jdx + 1
Loop
End If
' redefine LOV name to contain all current valid choices
LOVL2.CurrentRegion.Name = LOVL2.Name.Name
End Sub
In your case, as the data seems to be more or less static, you can copy all valid selections from [Prod_Release] to LOV at Sheet_Activate or any appropriate activation trigger.
Hope this helps .... good luck MikeD

Trying to use VBA-excel to filter one worksheet based on clicked value in another workseet

OK, I'm a total VBA noob, so excuse my awful code.
I have two excel worksheets, one titled 'Contractors' and one titled 'Referring_to_Contractors'.
The contractors sheet is laid out like so.
Terr ContractorID First Last
1 7 Bob Smith
2 5 Jeff Brown
3 8 Stan Lee
The Referring_to_Contractors sheet has the same fields and layout as the Contractors sheet above, but also has additional columns for Referring Contractors, so it has columns titled "Ref_Contractor_Id", "Ref_First", "Ref_Last", etc.
What I'm trying to do is use VBA so that when someone double clicks a row in the "Contractors" sheet, it will take the value in the Contractor_ID column, then look in the "Referring_to_Contractors" sheet and filter by all records in that sheet that have that value as Contractor_ID. Essentially, this would display referral information for the Contractor_ID clicked on the first sheet. I created a named range for the Contractor_ID field titled "PrimaryContractor"
So, on the first sheet 'Contractors', I have:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
End Sub
and..
Sub Select_Ref_Contractors()
ContractorId = Range("PrimaryContractor").Value
With Sheets("Referring_to_Contractors")
.Visible = True
.Select
End With
ActiveSheet.Range("$B$10:$N$44163).AutoFilter Field: =1, Criteria1:= ContractorID
Application.Goto Range("A1"), True
End Sub
Conceptually this seems like it should be pretty simple yet for some reason I can't get the second sheet to filter correctly.
Any helps or even useful links would be greatly appreciated.
I have just knocked this up in Excel 2007 and it seems to work
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim id As String
If Not Target.Cells.Count > 1 Then
id = CStr(Selection)
Sheet2.Activate
Sheet2.Range("A1", "c4").AutoFilter 1, id
End If
End Sub
It is using the same table on both sheets as below and when you double click a cell on Sheet1, the BeforeDoubleClick event fires and puts you onto Sheet2 with the filter applied.
ID ID2 Text
1 2 a
2 2 b
3 3 c

Resources