Google Docs Spreadsheet display data from row matching a criteria - filter

Basically, I would like Sheet 1 to pull data FROM Sheet 2, renamed to 'Loot'. However, the data that is pulled from 'Loot' can only be from a specific column, and two other cells in the same row must contain specific data from Sheet 1.
Example: 'Loot' has the following important Columns for B, C, and D: Character, Item Type, and Quantity
I want a cell in Sheet 1 to contain a Quantity(D) value from 'Loot', but only if the Character(B) and Item Type(C) cells that share the same row as the data that is being pulled matches that of two specific cells on Sheet 1.
This is as close as I could come without success.
=QUERY('Loot'!D2:D;"select * where (B matches A14 and C matches A8)";1)
Here is a temporary link to the spreadsheet.
https://docs.google.com/spreadsheet/ccc?key=0AgUUnVW8yWhXdHhsZnpac29LdjdhTG9adFg4NnhwVHc&usp=sharing
Sheet 1 is Veldspar
Sheet 2 is Loot
With the help of a friend, I'be been able to get this far...
=QUERY('Loot'!B2:D100,"select (D) where B = '" & A14 & "' and C = '" & A8 &"'")
The problem is that if there is more than one result, instead of adding it together, it just displays each result in each cell below it
EDIT
Fixed all the issues and found another one.
=SUM(QUERY('Loot'!B$2:D,"select (D) where B matches '"& $A14 &"' and C matches '" & A$8 &"'"))
The problem now is that if there is no criteria to pull data from, the cell produces a #N/A error which causes all other cells that reference its data to be unable to calculate their data.
EDIT..
So far so good, this is what I used to fix the issue
=IFERROR(SUM(QUERY('Loot'!B$2:D,"select (D) where B matches '"& $A14 &"' and C matches '" & A$8 &"'")),"0")
EDIT..
That last one edit the trick. My problem has been solved. I left the link available to all and just changed all the names located in the Loot 'sheet' in order to hide names.

Answering my own question :)
=IFERROR(SUM(QUERY('Loot'!B$2:D,"select (D) where B matches '"& $A14 &"' and C matches '" & A$8 &"'")),"0")

Related

FILTER values from one sheet when not present on another

I'm trying to compare Items in "projectEstimate!D2:D & projectEstimate!E2:E" to Items in 'itemsAssociations!C3:C & itemsAssociations!D3:D" for matches.
If there is a match, confirm that the associated item (itemsAssociations!G3:G & itemsAssociations!H3:H) is not already listed in "projectEstimate".
If it is not listed, print that item. If it IS listed, do nothing.
I put together the following code which seems like it should work, but the item prints whether it's present on projectEstimate or not.
=ArrayFormula({itemsAssociations!I2:J2;FILTER(itemsAssociations!I3:J,
{projectEstimate!D2:D&IF(LEN(projectEstimate!E2:E),projectEstimate!E2:E,)=itemsAssociations!C3:C&IF(LEN(itemsAssociations!D3:D),itemsAssociations!D3:D,)},
{projectEstimate!D2:D&IF(LEN(projectEstimate!E2:E),projectEstimate!E2:E,)<>itemsAssociations!G3:G&IF(LEN(itemsAssociations!H3:H),itemsAssociations!H3:H,)}
)})
I also tried this QUERY, but not sure how to include the entire ranges
=QUERY(itemsAssociations!C3:J,"SELECT I,J WHERE C = '"&projectEstimate!D2:D&"' AND D = '"&projectEstimate!E2:E&"' AND J != '"&projectEstimate!D2:D&"'",0)
This is close, but the opposite result:
=FILTER(projectEstimate!D2:D,COUNTIF(FILTER(itemsAssociations!J3:J,COUNTIF(itemsAssociations!C3:C&itemsAssociations!D3:D,itemsAssociations!C3:C&itemsAssociations!D3:D)),projectEstimate!D2:D))
My sheet
it would be something amongst theses lines:
=ARRAYFORMULA(REGEXREPLACE(QUERY(FILTER(projectEstimate!D2:D&":"&projectEstimate!E2:E,
NOT(COUNTIF(itemsAssociations!C3:C&":"&itemsAssociations!D2:D,projectEstimate!D2:D&":"&projectEstimate!E2:E))),
"where Col1 is not null", 0), ":$", ))
This is what I came up with...
=IFERROR(FILTER(FILTER(itemsAssociations!J3:J,NOT(COUNTIF(projectEstimate!D3:D,itemsAssociations!C3:C))),NOT(COUNTIF(FILTER(projectEstimate!D2:E,NOT(COUNTIF(itemsAssociations!C3:C&itemsAssociations!D3:D,projectEstimate!D2:D&projectEstimate!E2:E))),FILTER(itemsAssociations!J3:J,NOT(COUNTIF(projectEstimate!D3:D,itemsAssociations!C3:C)))))),"No suggested items!")

AddField function does not work as expected

I have the following block of code that iterates through the fields of each table and adds the fields of the current table respectively in order to create a number of tableboxes.
'iterate through every table
For i=1 To arrTCount
'the arrFF array holds the names of the fields of each table
arrFF = Split(arrFields(i), ", ")
arrFFCount = UBound(arrFF)
'create a tablebox
Set TB = ActiveDocument.Sheets("Main").CreateTableBox
'iterate through the fields of the array
For j=0 to (arrFFCount - 1)
'add the field to the tablebox
TB.AddField arrFF(j)
'Msgbox(arrFF(j))
Next
Set tboxprop = TB.GetProperties
tboxprop.Layout.Frame.ObjectId = "TB" + CStr(i)
TB.SetProperties tboxprop
Next
The above code creates the tableboxes, but with one field less every time (the last one is missing). If I change the For loop from For j=0 To (arrFFCount - 1) to For j=0 To (arrFFCount) it creates empty tableboxes and seems to execute forever. Regarding this change, I tested the field names with the Msgbox(arrFF(j)) command and it shows me the correct field names as I want them to be in the tableboxes in the UI of QlikView.
Does anybody have an idea of what seems to be the problem here? Can I do this in a different way?
To clarify the situation here and what I have tested so far, I have 11 tables to make tableboxes of and I have tried with just one of them or some of them. The result I am seeing with the code is on the left and what I am expecting to see is on the right of the following image. Please note that the number of fields vary for each table and the image has just one of them as an example.

Excel VBA, multi parameter filter to return row ID

I currently have an algorithm that manipulates data on sheet 24 in my excel workbook. I have 3 integers, a, b, and c, that come from data on sheet 24, and I need to use them to return a unique row ID on sheet 14. A, B, and C, each represent their corresponding Column (range) on sheet 14 IE: Int a from sheet 24 is in column A on sheet 14. Int b in column b, and c in c. The numbers combined will always return a singular row ID from 14, in the case, integer row. I'm having a hard time writing a statement with Filter, evaluate, and a bunch of other Excel functions. Does anyone know how to launch a script from an algorithm executing on one sheet and just pull a row ID in sheet 14 using its' resulting three search numbers for a,b,c?
row = Sheets("Physical Disk Details").Columns("A").Find(what:=a, LookIn:=xlValues, lookat:=xlWhole) * Sheets("Physical Disk Details").Columns("B").Find(what:=b, LookIn:=xlValues, lookat:=xlWhole) * Sheets("Physical Disk Details").Columns("C").Find(what:=c, LookIn:=xlValues, lookat:=xlWhole)
This Function will return the first row number that is found to exactly match what is provided for a,b, and c. It demonstrates one of the simplest Range iteration and If/Then tests that forms the foundation of most data pattern searching subroutines you will find for Excel VBA. There are ways to streamline this code but it demonstrates the basic principle.
If you read every line of this code and understand what all of it does you can use the principles to accomplish most tasks even vaguely similar to it.
Function GetRowNumberByABCMatch(a As Integer, b As Integer, c As Integer) As Integer
Dim lastRowInDataSet As Integer
Dim i As Integer
'get last row containing data in column 1
lastRowInDataSet = Sheets("Physical Disk Details").Cells(Rows.count, 1).End(xlUp).Row
'i = current row number, start at row 1
For i = 1 To lastRowInDataSet
If Sheets("Physical Disk Details").Range("A" & i).Value = a _
And Sheets("Physical Disk Details").Range("B" & i).Value = b _
And Sheets("Physical Disk Details").Range("C" & i).Value = c Then
'all fields match, return the current row number
GetRowNumberByABCMatch = i
'stop processing and return because we found a single match
Exit Function
End If
Next i
'didn't find a matching row, return -1
GetRowNumberByABCMatch = -1
End Function

Parts of an unsorted list into a drop down

I am trying to create a data validation drop down cell that displays a list of values pulled from a much larger list, but only the ones where the lookup value meet certain requirements. This would be like the SUMIF function that only adds the values where the lookup value meet certain requirements. Here is an example of my list:
V F
Apples x
Bananas x
Tangerines x
Tomatoes x x
Broccoli x
Pears x
Kiwis x
Plums x
Water melon x
Squash x x
I want only the ones with an "x" in the first column to display in the drop down.
Tomatoes
Broccoli
Squash
Also the original list can't be sorted. I am fine with using macros if that would work. I am using Excel 2010.
If you want a range of valid entries without blanks to use as a list for data validation, I suggest something like:
=INDEX($A$2:$A$11,SMALL(IF($B$2:$B$11<>"",ROW($A$2:$A$11)-ROW($A$2)+1),ROWS(C$2:C2)))
entered with Ctrl+Shift+Enter
There is about 20 minutes of explanation at https://www.youtube.com/watch?v=6PcF04bTSOM.
Without using VBA, you could create a copy of the list that is filtered. You can then reference the cells in that copy when you use data validation.
For example, you could do the following steps for your example above:
Apply a filter to the list where only those showing an x in the first column are showing. Copy the filtered list, then paste to another spot on the worksheet. Turn off the filter on the list, so it returns to normal. Go to the cell that you want to add a validation drop down to, and select data validation. Select list, then reference the copied list.
Using VBA, you could use this as a starter. The key is the Range.Validation method, which is explained in detail here. This reads your list in column A, finding those with an "x" in column B, and puts that in a validation list in cell E1.
Dim myvalidation_list As String
Dim last_row As Long, current_row As Long
last_row = Cells(Rows.Count, "A").End(xlUp).Row
For current_row = 1 To last_row
If LCase(ActiveSheet.Cells(current_row, 2).Value) = "x" Then
'put in the delimiting "," if the list already has an entry
If myvalidation_list <> "" Then
myvalidation_list = myvalidation_list & ","
End If
'add to the validation list
myvalidation_list = myvalidation_list _
& ActiveSheet.Cells(current_row, 1).Value
End If
Next
With ActiveSheet.Range("E1").Validation
.Delete
.Add Type:=xlValidateList, Formula1:=myvalidation_list
End With

QTP narrow a list of ChildObjects

[The description is a bit fudged to obfuscate my real work for confidentiality reasons]
I'm working on a QTP test for a web page where there are multiple HTML tables of items. Items that are available have a clickable item#, while those that aren't active have an item# as plain text.
So if I have a set of ChildObjects like this:
//This is the set of table rows that contain item numbers, active or not.
objItemRows = Browser("browserX").Page("pageY").ChildObjects("class:=ItemRow")
What is the simplest way in QTP land to select only the clickable link-ized item #s?
UPDATE: The point here isn't to select the rows themselves, it's to select only the rows that have items in them (as opposed to header/footer rows in each table). If I understand this correctly, I could then use objItemRows.Count to count how many items (available and unavailable) there are. Could I then use something like
desItemLink = Description.Create
desItemLink("micclass").value = "Link"
objItemLinks = objItemRows.ChildObjects(desItemLink)
To get the links within only the item rows?
Hope that clarifies things, and thanks for the help.
I think I have this figured out.
Set desItemLink = description.create
desItemLink("micclass").value = "Link"
desItemLink("text").RegularExpression = True
//True, Regex isn't really required in this example, but I just wanted to show it could be used this way
//This next part depends on the format of the item numbers, in my case, it's [0-9]0000[0-9]00[0-9]
For x = 0 to 9
For y = 0 to 9
For z = 0 to 9
strItemLink = x & "0000" & y & "00" & z
desItemLink("text").value = strItemLink
Set objItemLink = Browser("browser").Page("page").Link(desItemLink)
If objItemLink.Exist(0) Then
//Do stuff
End If
Next
Next
Next
Thanks for your help anyways, but the code above will iterate through links with names in a given incrementing format.

Resources