I'm trying to change view selection formula by script with this selection formula:
formula = "SELECT (#Modified = [" & Left(doc1.LastModified,10) & "]) & form = ["& Cstr(doc1.form(0)) &"]"
But when I try to execute it Notes retrive me the following error:
Notes error: Unknown [KeyWord] for #Function (SELECT (#Modified = [03/02/2015]) & form=[myform])
You should use quotes for form instead of square brackets.
Here is example:
formula$ = {SELECT (#Modified = [} & Left(doc1.LastModified,10) & {]) & form = "} & doc1.form(0) & {"}
Which generate this string:
SELECT (#Modified = [03/02/2015]) & form = "myform"
Related
I need to get the NumberFormat from an excel file (appr. 3000 lines) and I wrote a simple Script which copy it from column A to column C each row by row. I tried to use this script with Power Automate after 10 minutes.
I already set the timeout on 60 minutes, but it seems that my tenant configuration abort it always after exactly 10 minutes.
Here is my script:
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheets()[0]
let range = sheet.getUsedRange(true);
let rows = range.getUsedRange(true).getRowCount();
let cols = range.getUsedRange(true).getColumnCount();
for (let row = 2; row <= rows; row++) {
sheet.getRange("C" + row).setValue(sheet.getRange("A" + row).getNumberFormat())
}
}
Is there an easier way to copy the NumberFormat from one column to another and does anybody know a better way?
Please make sure when you ask these questions to put the Office-Scripts tag since this is Office Scripts. You don't need to loop to achieve this. You can use getNumberFormats() like in the code below.
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheets()[0];
let rowCount = sheet.getUsedRange(true).getRowCount();
let numFormats = sheet.getRange("A1:A" + rowCount).getNumberFormats();
let newRng = sheet.getRange("C1:C" + numFormats.length).setValues(numFormats);
}
EDIT 4/23/21
If you just want to get the indent levels, then you could just insert this formula in column C rather than getting the number formats.
=IFERROR(LET(indentLevel,FIND("[",FILTER(A:A,A:A<>""),1),SWITCH(indentLevel,4,1,6,2,8,3,10,4,12,5)),"Other Formula Here")
Here is the Office Scripts
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheet("Sheet1");
sheet.getRange("C1")
.setFormulaLocal("=IFERROR(LET(indentLevel,FIND(\"[\",FILTER(A:A,A:A<>\"\"),1),SWITCH(indentLevel,4,1,6,2,8,3,10,4,12,5)),\"Other Formula Here\")");
}
Here is my VBA code where I use a for loop:
Sub GetHierachyParents()
Set appExcel = holeAnwendung("Excel.Application")
Set wbkExcel = appExcel.Workbooks.Open("C:\impport.xlsx")
Set wksExcel = wbkExcel.Sheets("Hierachy")
countRows = wksExcel.Range("A1").End(xlDown).Row
For i = 2 To countRows
Node = 0
If (Len(wksExcel.Range("A" & i).NumberFormat) - Len(Replace(wksExcel.Range("A" & i).NumberFormat, "[-]", "")) > 0) Then
IndentLevel = (Len(wksExcel.Range("A" & i).NumberFormat) - Len(Replace(wksExcel.Range("A" & i).NumberFormat, " ", "")) - 1) / 2
Node = -1
Else
IndentLevel = (Len(wksExcel.Range("A" & i).NumberFormat) - Len(Replace(wksExcel.Range("A" & i).NumberFormat, " ", "")) - 5) / 2
Node = 0
End If
sql = "INSERT INTO impTemp0 (F1, F2, F3, F4) VALUES ('" & wksExcel.Range("A" & i) & "', '" & Replace(wksExcel.Range("B" & i), "'", "") & "', " & IndentLevel & ", " & Node & ")"
CurrentDb.Execute sql
Next i
CurrentDb.Execute "UPDATE [impTemp0] SET Parent = DMAX('id','[impTemp0]','[impTemp0].id<' & [impTemp0].id & ' AND [impTemp0].Level=' & [impTemp0].Level-1 & '')"
End Sub
And here is an example for the first 8 rows:
" [-] "#
" [-] "#
" [-] "#
" [-] "#
" [-] "#
" "#
I have an Excel file with a userform where users can insert exchange rates and different parameters for financial report.
I set up a DB file and I want to select rows based on the values in BV column (book value) and it should be higher than 100.000EUR.
The problem is that I have three other currencies besides EUR and I need to calculate EUR amount based on exchange rate.
I made an exchange rate field in my userform (BVAL is EUR default, and I also have BVGBP, BVPLN and BVRSD, which are 100.000EUR divided by each exchange rate).
This works:
SqlQuery = " SELECT * FROM Sheet1 where (bv>=" & BVAL & " and Currency = 'EUR')";"
But when I try to combine multiple results, syntax is not working. I tried other solutions found online.
SqlQuery = " SELECT * FROM Sheet1 where (bv>=" & BVAL & " and Currency='EUR') or (bv>=" & BVGBP & " and Currency='GBP') _
or (bv>=" & BVPLN & " and Currency='PLN') or (bv>=" & BVRSD & " and Currency='RSD');"
You SQL syntax is correct, but your VBA is not. Also, for better readability, break up the long lines:
SqlQuery = " SELECT * FROM Sheet1 where " & _
"(bv>=" & BVAL & " and Currency='EUR') or " & _
"(bv>=" & BVGBP & " and Currency='GBP') or " & _
"(bv>=" & BVPLN & " and Currency='PLN') or " & _
"(bv>=" & BVRSD & " and Currency='RSD');"
I need help fixing my conditions. I have 3 columns (Case #, Analyst & Status). I need to display a certain Analyst plus all status that aren't closed.
Dim c As String
Dim use As String
use = LabelUser.Caption
c = "Closed"
SQL = "SELECT * FROM tbl_Raw WHERE Analyst = '" & use & "' OR Status <> '" & c & "'"
this statement displays all cases under the analyst, including closed (c).
I tried this but it displays nothing.
SQL = "SELECT * FROM tbl_Raw WHERE Analyst = '" & use & "' AND Status <> '" & c & "'"
It's been a long time since this question has been made, however, it still worth answering.
Whenever you use SQL statement within ADO connection, you must assign brackets around and dollar sign at the end of the Table's name. E.g: "SELECT * FROM [tbl_Raw$] WHERE Analyst = '" & use & "' OR Status <> '" & c & "'"
I have a database in access where every data has a date and time in two different columns.
I need to to run a query in excel using VBA which would fetch me data between two specific dates and times (eg: 01/05/2016 13:15 and 03/05/2016 10:11)
My query is as follows:
SQL = "SELECT * FROM " & database & " WHERE symbol='" & companyName & _
"' AND AdmitDate BETWEEN " & (fromDate + fromTime) & " AND " & (toDate + toTime) & ""
However, it gives me a syntax error which says:
'Missing operator in query expression'
I am not able to figure out where I have gone wrong.
Please help!
You need the right string expressions for the date/time values. Format can create these:
SQL = "SELECT * FROM " & database & " WHERE symbol='" & companyName & "' AND AdmitDate BETWEEN #" & Format(fromDate + fromTime, "yyyy\/mm\/dd hh\:nn\:ss") & "# AND #" & Format(toDate + toTime, "yyyy\/mm\/dd hh\:nn\:ss") & "#"
I did a little bit of reading on what I am about to ask, but I couldn't find a specific answer.
I am writing a program in VBScript that will read an excel file and then update an Access Database.
It works great, but the problem I can foresee running into is thus:
What happens when the excel file has a blank on a specified field? I don't want the script file to update a "blank" to the database, I want it to be left unchanged in the database ONLY if there is a blank in the excel file. If not, proceed as normal.
Currently, it will read this as a blank and insert the blank into the row in my database.
Is this possible? For the script to basically ignore fields it reads (in Excel) that are blank while only updating (in the database) the fields that actually have data (in Excel) in them?
Currently, it says no in the field in the database. This is just a brief code example. In the Excel sheet, it says yes in the correct column.
Do Until objExcel.Cells(intRow,1).Value = ""
asset_Tag = objExcel.Cells(intRow, 1).Value
ebay = objExcel.Cells(intRow, 2).Value
intRow = intRow + 1
objRecordSet.Open "UPDATE Test SET Listed_Ebay = '" & ebay & "' WHERE Asset_Tag = '" & asset_Tag & "'", _
objConnection
Loop
If you are reluctant to add 20 If statements to your code, surely you could put Excel's native COUNTA functionality to make sure that there are 20 values before the update operation.
With objExcel
Do Until .Cells(intRow,1).Value = ""
If .Application.CountA(.Cells(intRow, 1).Resize(1, 20)) = 20 Then
asset_Tag = .Cells(intRow, 1).Value
ebay = .Cells(intRow, 2).Value
objRecordSet.Open "UPDATE Test SET Listed_Ebay = '" & ebay & "' WHERE Asset_Tag = '" & asset_Tag & "'", objConnection
End if
intRow = intRow + 1
Loop
End With
I had a guess a bit as to which 20 values were intended to be filled but I think you can get the idea.
EDIT NOTEĀ¹: reordered the code lines to maintain the intRow according to the loop.
EDIT NOTEĀ²: You may want to conditionally pass the original value back into the UPDATE query if the LEN of the new value is zero.
Dim qry as String
qry = "UPDATE Test SET " & _
"Listed_Ebay = Iif(CBool(Len('" & ebay & "')), '" & ebay & "', Listed_Ebay), " & _
"Listed_Amazon = Iif(CBool(Len('" & amzon& "')), '" & amzon & "', Listed_Amazon), " & _
"Listed_POS = Iif(CBool(Len('" & pos& "')), '" & pos & "', Listed_POS) " & _
"WHERE Asset_Tag = '" & asset_Tag & "'"
objRecordSet.Open qry, objConnection
I'm just making stuff up past the original one field example you provided but you should be able to transcribe this for your own 8 fields. I'm using LEN here on text values but comparing numbers to zero (or even their LEN would be appropriate.