How can I check the time a cell was edited and set the time and date in other cells? Google script - scripting

I have spreadsheet and I'm basically going to use it for inventory tracking and management.
In one sheet I'll have an app on my phone fill a list when it reads
a QR code.
In the second sheet there is also a list with the
specific QR codes of each item.
I need to know when a cell in the first sheet has been updated and put that information in the following two cells.
I'm using this trigger to check if ANY cell in the document has been updated.
function cellEditTrigger()
{
ScriptApp.newTrigger('coolFunction').forSpreadsheet('awsomeSpreadsheetID').onEdit().create();
}
It works fine and it runs the 'coolFunction' function. However I can't seem to be able to get the time and date for the cells that have been edited and put that information in the next two cells.
I know I could use onEdit(e), but I still can't get the information from e.range and I would like my script to not have to be bound to the Spreadsheet.
Is there any way to accomplish this?

Related

Excel Creating A Cell with multiple functionality

I have a workbook with multiple sheets. On the first and second sheets I have a drop down selector using 'Data Validation', the data is on hidden sheets that are created from an external data source. I am using INDEX and MATCH to display the data.
For Example
|data_field_1|=INDEX(workSheet,MATCH(prevCell,workSheet[field],0),MATCH(workSheet[#Headers],0))|=prevCell|
where | is the cell boundary. So the field name in the first cell is used to retrieve the data I wish to display in the second cell and the data is then displayed in the 3rd cell.
So what I am trying to do is drive the second worksheet from the first, but also have the functionality in the same cell to also retrieve a different set of data if I require.
Scenario
If I have on the first page a drop down that has the values, 'AC/DC', 'Black Sabbath', 'Rush'. When I select 'AC/DC', on the second page what should then be displayed in the Drop Down is the Value 'High Voltage'. However I can also use this drop down to select other values, 'Dirty Deed', 'Let There Be Rock'. If I then go back to the first Page and instead pick 'Rush', I would expect the display on the second page to display 'Rush' with the drop down values that can be selected 'Fly By Night', 'Caress of Steel', '2112', ...
What is happening at the moment is I can get the first bit to work. When I pick AC/DC, on the second page I get 'High Voltage', however when I select from the second page 'Dirty Deeds' and then go back to page one and select 'Rush', I still have 'Dirty Deeds' on the second page instead of 'Rush'.
Is this possible to do? I have no experience with VBA, though if this is the way to fix my problem I would love to know the solution.
Many Thanks

Referencing a sheet by index number

I've got a LibreOffice Calc spreadsheet that I use to keep track of my accounts receivable at work. Each sheet lists invoices and their status (paid, unpaid, etc) as well as info about each invoice. I'm trying to create a Summary sheet that lists certain data from each sheet. Creating the sheet manually is easy, but I'm trying to "automate" the process. I want the summary page to auto-update if I add a new sheet (or remove one) as I add and remove accounts to the file.
I know that LibreOffice assigns each sheet an index number that I could refer to in some sort of formula, but I cannot find a function that I can use to refer to that index number when getting a value from a cell within it. One would expect that a function like Sheet(2) would reference the second sheet, but, alas, that is not so!
I've tried using the indirect and address functions without success, but I'm not sure if I'm not understanding these functions or if they're not appropriate for what I'm trying to accomplish.
This has been a missing piece in Calc for a long time. The preferred solution is to write a user-defined function. Spreadsheet formulas do not access sheets by index number but Basic can.
The following function is from https://ask.libreoffice.org/en/question/16604/how-do-i-access-the-current-sheet-name-in-formula-to-use-in-indirect/.
Function SheetName(Optional nSheet)
If IsMissing(nSheet) Then
SheetName = ThisComponent.getCurrentController().getActiveSheet().getName()
Else
SheetName = ThisComponent.getSheets().getByIndex(nSheet-1).getName()
EndIf
End Function
Then get a relative address of the first sheet cell A1 like this.
=ADDRESS(1,1,4,,SHEETNAME(1))
A slightly different function is given at https://forum.openoffice.org/en/forum/viewtopic.php?f=9&t=49799.

Excel VBA - Pull information into user form to update

I am trying to create a userform that allows the users to update issues stored in a specific sheet (called Issues List). I have built a dropdown list using data validation that allows the user to select the unique issue name from a list. I have created a button next to that dropdown which opens up the userform and correctly imports the issue name identified from the dropdown.
What I need to figure out is, when the user form is initiated how do I have it search column B in my Issues List sheet and identify which row contains the issue selected by the user, and populate the fields of the user form with the information found in rows C-X of the Issues List sheet.
What I have been trying to use is an index match function, but have been unsuccessful in getting the code to work. An example of what I have been using is:
Resolved.Value = Application.WorksheetFunction.index
('Issue List'!$X$2:$X$1000,Application.WorksheetFunction.match
('Priority Table'!I35,'Issue List'!$B$2:$B$1000,0))
Any help would be greatly appreciated.
Thanks in advance!
When you use Worksheet Functions in VBA, you still have to pass in the ranges using VBA language:
So instead of:
'Issue List'!$X$2:$X$1000
you would use:
Worksheets("Issue List").Range("X2:X1000")
And instead of:
'Priority Table'!I35
Just use:
Worksheets("Priority Table").Range("I35")
Note that you can also refer to ranges by names, which can make coding easier and also far safer. When you insert rows in spreadsheets, Excel doesn't automatically update ranges in any VBA code. A reference to I35 will always to be I35.
Instead, define a name for cell I35 in Excel as normal, then refer to it in the code.
For example, if you name I35 as "Issue"
You can refer to the cell by:
Range("Issue")
(If it is a global variable, which it is be default as long as it's a unique name in the workbook, you don't need to use the Sheets("Priority Table") qualifier.
Refer to this documentation for more info on how to refer to ranges in Excel from VBA:
https://msdn.microsoft.com/en-us/library/office/gg192736(v=office.14).aspx

Need to Update External References in an Excel Sheet while a Macro is Running

I have an excel macro that sets Cells to an external location.
Range(NamedReference) = "='http://webaddress/ExcelSheet.xlsx'!NamedReference
Other cells use that location to calculate new values.
"A1" = NamedReference + 1
The problem is that I need to read the new calculated values back into the macro to export data, but the external link has not yet been calculated to any value. It is a #NAME? until the macro is done running. Is there any way to force excel to get those values during the macro run time?
I have tried a variety of things including
Calculate
CalculateFull
Any help would be appreciated. My current solution is to just close the macro on error and have the user re run the macro, but it is really kludgey.
**Edit: Forgot equals sign in formula
You could try
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
See on MSDN

Show Cell Range on UserForm; then update

I've been using a crude method to help the user update some cells - by having them in a sheet. Is there any way I can display the various ranges in a userform, one by one, then have the user update them, click a button and move onto the next one?
Essentially, can I have Excel automatically generate an input form based on a range? The process of updating and saving back to the sheet I can do; it's the production of the correct form that I can't.
It's possible to do this, but the only way I can think of is to make a userform that automatically populates itself based on a range passed in. This way you could have different macros in Excel that call the form to populate based on different ranges. I built a proof of concept Excel file for trying this, and it seems to work, the only issue I can think of being that you need to figure out a way to tell the user what input field is what.
I think what needs to be done is to add controls programmatically to a userform (I name the textboxes as the cell address it's going to populate) then when the form is closed loop through all the textboxes and populate the cells with the textbox values.
You can see what I did at:
https://my.syncplicity.com/share/uicgbs3rl0/InputForm.xls
I think all that would need to be done is for you to work out how to add labels for the textboxes, and make sure the form is resized based on the controls you add...
I am not quite shure what you are looking for, but you could insert a second sheet and use it as a "form". An other way could be a dialog box with an input field.
Either way, you present the cells you want the user to change one by one, using a vba-function. You implement a "previous field" and a "next field" button, so the user can step through the range of cells. If the user hits "next field", you save his input and take the next cell from a previous defined range of cells.
You could have a "config field" in which you define the range of cells you want to change.
This is pretty rough and old-fashioned but if you have the data in standard list format - i.e. column headers in the first row of your range and then one record of data in each row below - then selecting a cell within the range and going Data > Form will give you a crude input form with roughly the functionality you need.
You can also do this in VBA by calling the ShowDataForm method of the appropriate worksheet. Just select a cell within whichever range you need first. The macro will remain paused until the user closes the data form