Find result then range and copy - function

I'm having some trouble trying to make a function that acts like vlookup but returns a range rather than a cell
The data to search through looks like this
Sometimes there is a space separating sometimes not
What I would like to do is to look up 16 from my main page and return all the values in that range.
the code I currently am using will only return the first line in a messagebox
Public Function findrulepos(target) As Range
Dim ruleStart, ruleEnd, ruleEnd2 As String
Dim RuleRange As Range
'Dim ruleEnd As Range
MaxRule = 100000
MaxRow = 100000
Set target = Sheets("main").Range("E2")
Sheets("ResRules").Select
For i = 3 To MaxRow
If CStr(ThisWorkbook.Sheets("ResRules").Range("A" & i).Value) = _
CStr(target.Value) Then
ruleStart = _
ThisWorkbook.Sheets("ResRules").Range("A" & i).Offset(0, 1).Text
Exit For
Else
End If
Next i
End Function

If we can assume that the numeric group labels in col A are sequential, then I think this will achieve what you need:
Enter the numeric label you are wanting to extract (16 in your example) into cell E1
Note that =MATCH(E1,A:A,0) gives us the row number where group 16
starts, which is the first row we want to copy. Similarly,
=MATCH(E1+1,A:A,0) gives us the row number where group 17 starts,
which is one row below the last row we want to copy. (Unfortunately
that's not true for the very last group of code, but to rectify that
you just need to add a dummy number at the very bottom of the data
in col A.)
Enter the formula =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1),"") in F1. That should copy the first value of the selected code block -- [DO] ADD TO QUEUE P in your example.
Copy F1 down as many rows as the largest code block is likely to be.
The one problem with that is that it will put 0 whenever it copies a blank row. So you have to explicitly check for that case, e.g. by changing the formula in F1 to =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),IF(ISBLANK(INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"",INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"")

Related

How to combine many query in spreadsheet if one or more query is empty

Problem
I have some data from spreadsheet and want to match with date with query, and combine many query.
Question
My query will work if all col i choose is'nt empty. But my data (col) will not all be filled, some will be left blank. If I try with my query one data blank don't want to appear.
Example
=IFERROR({IFERROR(QUERY(dashboar_data;"SELECT C,I WHERE J = date'" & TEXT(DATEVALUE(B5);"yyyy-mm-dd") & "'";0);dashboar_data/0);
IFERROR(QUERY(dashboar_data;"SELECT C,M WHERE N = date'" & TEXT(DATEVALUE(B5);"yyyy-mm-dd") & "'";0);dashboar_data/0);
IFERROR(QUERY(dashboar_data;"SELECT C,Q WHERE R = date'" & TEXT(DATEVALUE(B5);"yyyy-mm-dd") & "'";0);dashboar_data/0)})
Its will work if 3 col is filled, i want if one col empty other query still work
You may try to fake data with iferror. Produce the same number of columns with empty values:
iferror (... , {""\""})

Check highest digit and copy text from grid cell

I'm new to scripting, but need to do the following in Google sheet script for my RPG gaming system...
Check a cell for the highest one-digit number. i.e. 1 6 3 2 4 = 6 highest number.
Check the same in another cell.
Depending on the combo of these digits, i.e. 6-2, 3-4, 1-6 etc, text from a specific cell in a grid table on another sheet should be copied.
The grid has 1 to 6 vertically, and 1 to 6 horizontally, different texts in each combo cell.
The copied text shall be entered into a specific cell (i.e. E10) in the first sheet.
Can someone help me?
From what I see, you would like to check the highest value in two cell, and would like to use that to get an exact location in a table of values, and get that value printed on another cell.
The problem can be solved in 3 phases.
1) Finding the highest value in the cell.
2) Retrieving the value in the table.
3) Setting the destination cell with the retrieved value.
1) Depending on if you are finding the highest value in a cell refers to:
A) 1534 in one cell and taking 5
OR
B) 1 in A1, 5 in A2, 3 in A3 and 4 in A4. and retrieving 5 from A2 cell.
A: Your solution would use a combination of .split() & Array.prototype.concat.apply() & Math.max.apply(). Reference: Inputting an array into Math.Max in Google Apps Scripts
B: Your solution would use a combination of getRange(row,column,row,column) & Array.prototype.concat.apply() & Math.max.apply()
You would get an output of two max number, which we would call A and B
2) To retrieve the value, you would require the getRange(A,B) & getValue() and depending on where the table is you might need to modify A and B to get the correct location in the table.
3) To set the value in cell E1, you would require the setValue() function.
You might want to try resolving the issue by yourself using the handles above. They might not be the most efficient, but should work. Alternatively i have a sample script below for you. There is a flaw, whereby if the value input is larger than your table, it would not flag out an error. so either you limit the users input or you would create a way to flag out the error:)
function SetRetrievedValue() {
var app = SpreadsheetApp;
var ss = app.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//var cellcontent1 = sheet.getRange(2,1,6,1).getValues(); use this if its a range of cells you are searching
var cell1 = sheet.getRange(1,1).getDisplayValue(); //gets value as string
var cellcontent1 = cell1.split(""); // splits up the string individually
var newcellcontent1 = Array.prototype.concat.apply([], cellcontent1); // flatten the array
var maxNum1 = Math.max.apply(null, newcellcontent1); //gets the max value in the array
// repeat of cell 1
var cell2 = sheet.getRange(1,2).getDisplayValue();
var cellcontent2 = cell2.split("");
var newcellcontent2 = Array.prototype.concat.apply([], cellcontent2);
var maxNum2 = Math.max.apply(null, newcellcontent2);
var tablecell = ss.getSheetByName("Table sheet").getRange(maxNum1,maxNum2).getValue(); //retrieve the value based on the corresponding max value
sheet.getRange(1,3).setValue(tablecell); // sets the cell C1 as the value retrieved from the table
}

How to get specific cell value in SSRS grouping?

I am making an SSRS report using SQL Server Report Builder. I have column and row grouping as follows :
I want to pick up the row that is highlighted in the red box below. How do I access that specific cell and display its value in some other table in the report? As you can see the value that I want to access is a column grouping total.
Use custom code:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
Next
return suma
End Function
Then in the cell where you want to reference the value:
=Code.Sumlookup(lookupset("2073/074",Fields!FiscalYear.Value,Fields!Value.Value,"DataSet"))
*
lookup("2073/074",Fields!FiscalYear.Value,Fields!Alfa.Value,"DataSet"))
As the cell you want does not have a specific design time name, you won't be able to reference it directly. You'll have to recalculate the value in your second table. You'll have to determine the criteria but assuming it always the last fiscal year and Particular = fixed percentage... then...
You should be able to do it with something like (untested)...
=SUM(IIF(Fields!FiscalYear.Value = Last(Fields!FiscalYear.Value) AND Fields!.Particular.Value = "Fixed Percentage of Gross Income [c=(axb)]", Fields!Value.Value,0))

Google Sheets Script .getValue() and .getDisplayValue() returning #REF For Some Reason

I had this function working before, but for some reason it is not working anymore.
This is a picture of the three pieces of data I am trying to collect. They have references to a couple other sheets in my file including some 'INDIRECT's. The following is the simple code I am trying to run to obtain the value of one of the pieces of data:
var ss = SpreadsheetApp.openById(logKey).getSheetByName("Investing");
var value = ss.getRange("G2").getValue();
var formula = ss.getRange("G2").getFormula();
Logger.log("Value: " + value + " Formula: " + formula);
... And this is the output:
[16-10-06 09:50:04:531 EDT] Value: #REF! Formula: =AD$2
As you can see from the output, it is successfully reading the cell from the spreadsheet, but it is not obtaining the value from the cell, just the formula. I don't understand why this is the case as in my sheet, the value it is trying to obtain is not '#REF!'.
As I said before, I had this general piece of code working before, but I must have changed something such that it broke what I am attempting to do.
Additional note: I am unsure if this code may be the culprit for some reason, even though it worked like this before. This is simply to convert columns numbers to row numbers form another sheet for easy copy and paste:
=INDEX(
INDIRECT(
CONCATENATE("QUOTES!",
REGEXEXTRACT(ADDRESS(ROW(), ((ROW()-3)*5)+4), "[A-Z]+"),
"4:",
REGEXEXTRACT(ADDRESS(ROW(), ((ROW()-3)*5)+4), "[A-Z]+")
)
),
COUNT(
INDIRECT(
CONCATENATE("QUOTES!",
REGEXEXTRACT(ADDRESS(ROW(), ((ROW()-3)*5)+4), "[A-Z]+"),
"4:",
REGEXEXTRACT(ADDRESS(ROW(), ((ROW()-3)*5)+4), "[A-Z]+")
)
)
)
)
Short answer
To avoid the #REF! error, the formula should not be placed on the second row. It could be placed on row 3 and below rows.
Explanation
ADDRESS(ROW(), ((ROW()-3)*5)+4) on any cell of row 2 returns the following error message:
Function ADDRESS parameter 2 value is -1. Valid values are between 1 and 18278 inclusive.

Freeze a date, once entered?

I use a sheet for project planning which has a column called "Status", where I can choose "Done" or "Open" from a pull down menu. In another cell, I enter my ECD (expected completion date).
I would like to set the status of a task to "Done" and another cell called ACD (actual completion date) should show the current date and freeze the cell after that. Using the function TODAY or NOW would always change the date, every day.
Is there a formula or script that could do that for me?
I love you COM VAT!
But don't be a naughty boy and not share your code...
Keep column A empty, upon form submission or an edit on the row column A will show the current date and it WILL NOT CHANGE :-)
function onEdit() {
var dateColNum = 1 //column F
var ss1 = SpreadsheetApp.getActiveSpreadsheet();
//set date in same row as edit happens, at fixed column
var nextCell = ss1.getActiveSheet().getRange(ss1.getActiveRange().getLastRow(), dateColNum, 1, 1)
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
Assume the "done" is in cell A1 and date/time in B1
=IF(A1="Done",IF(LEN(B1)>0,B1,NOW()),"")
however, you need to turn on iterations
also if you erase the "Done" the cell will be empty again
What you're looking for is a macro, not a formula. This solution assumes your ECD column is 'A' (column 1), then your STATUS column is column 'B' (column 2)
Step 1) Press Alt+F11, this will open up the code editor in VBA.
Step 2) Copy and paste the code below into your 'sheet' that your formula resides in.
Step 3) Save your workbook as a macro-enabled spreadsheet. (xlsm).
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
If (Target.Columns.Count = 1 And Target.Column = 2 And Target.Rows.Count = 1) Then
'Check every row, currently this will get executed once
For Each cell In Target.Cells
'Make sure the value is set to 'done'
If (UCASE(cell.Value) = "DONE") Then
'Using the current modified row, set column 1 to Today
'Note: Now() is the same as Today in VBA
Target.Worksheet.Cells(cell.row, 1).Value = Now()
End If
Next cell
End If
End Sub
Note: This macro only gets executed if only one cell gets set to 'done'. You can change it to work on multiple cells by removing the 'Target.Rows.Count = 1' part of the FIRST 'if' statement. This scenario may happen if you're 'extending' via clicking and dragging the 'done' value to multiple cells.
Note2: If you want to assign the date once, and prevent the date from ever changing, even if you modify the field to 'done' again. Change the last 'if' statement to the following:
If (UCASE(cell.Value) = "DONE" And Target.Worksheet.Cells(cell.row, 1).Value = "") Then