In Sheet Job Request When I choose a value from a list using a form button on the Job…
- User
In Sheet Job Request When I choose a value from a list using a form button on the Job Request Sheet I want the sheet to calculate, then 4 seconds later I want to copy all the values of cells with values fom column J of the sheet named in I2 of Job Request, and paste the copied values into a new text document line by line and have focus, activate the text document
- Assistant
for further editing if needed.
To accomplish this, you can use a combination of Google Apps Script and a timed trigger.
First, create your form button on the Job Request Sheet and add a trigger to it that runs the following script:
function submitFormAndCopy() { // Get the current sheet var sheet = SpreadsheetApp.getActiveSheet(); // Get the selected value from the list var selectedValue = sheet.getRange("B2").getValue(); // Change to your cell location // Perform calculations based on the selected value // Replace this with your own calculation code // Wait for 4 seconds Utilities.sleep(4000); // Get the sheet name from I2 var sheetName = sheet.getRange("I2").getValue(); // Get the data from column J of the specified sheet var dataRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).getRange("J:J"); var data = dataRange.getValues(); // Create a new text document var doc = DocumentApp.create("New Document"); // Iterate through the data and append each value as a new line in the document for (var i = 0; i < data.length; i++) { if (data[i][0] != "") { // Exclude empty cells var text = data[i][0] + "\n"; // Add a newline character doc.getBody().appendParagraph(text); } } // Open the new document var url = doc.getUrl(); var html = "<script>window.open('" + url + "', '_blank');</script>"; var userInterface = HtmlService.createHtmlOutput(html); SpreadsheetApp.getUi().showModalDialog(userInterface, 'New Document'); }This script first gets the selected value from the form button, performs any necessary calculations, and then waits for 4 seconds using the
Utilities.sleep()method.Next, it retrieves the sheet name from cell I2 and gets all the data from column J of that sheet using
getRange().getValues().The script creates a new text document using the
DocumentApp.create()method and then iterates through the data, appending each value as a new line in the document usingappendParagraph().Finally, the script opens the new document in a new browser tab using a modal dialog.
To set up the timed trigger, go to the "Triggers" section in the Script Editor and add a new trigger that runs the
submitFormAndCopy()function with a time-based interval of every minute:function createTimeBasedTrigger() { ScriptApp.newTrigger('submitFormAndCopy') .timeBased() .everyMinutes(1) .create(); }This trigger will run the
submitFormAndCopy()function every minute, but since the function includes a 4-second delay, it will not actually execute until 4 seconds after the form button is clicked. - User
I am using excel
- Assistant
To accomplish this in Excel, you can use VBA code and a timer event.
First, create your form button on the Job Request Sheet and go to the VBA Editor by pressing Alt+F11. Add a new module and paste the following code:
Public Sub SubmitFormAndCopy() ' Get the selected value from the list Dim selectedValue As String selectedValue = Range("B2").Value ' Change to your cell location ' Perform calculations based on the selected value ' Replace this with your own calculation code ' Wait for 4 seconds Application.Wait Now + TimeValue("0:00:04") ' Get the sheet name from I2 Dim sheetName As String sheetName = Range("I2").Value ' Get the data from column J of the specified sheet Dim data As Variant data = Worksheets(sheetName).Range("J:J").Value ' Create a new text document Dim doc As Object Set doc = CreateObject("Word.Document") doc.Application.Visible = True ' Iterate through the data and append each value as a new line in the document Dim i As Long For i = 1 To UBound(data) If Not IsEmpty(data(i, 1)) Then ' Exclude empty cells doc.Content.InsertAfter data(i, 1) & vbNewLine ' Add a newline character End If Next i ' Activate the text document doc.Activate End SubThis code is similar to the Google Apps Script code, but with some differences in syntax. It first gets the selected value from the form button and performs any necessary calculations, and then waits for 4 seconds using the
Application.Waitmethod.Next, it retrieves the sheet name from cell I2 and gets all the data from column J of that sheet using
Worksheets.Range().Value.The code creates a new text document using
CreateObject("Word.Document")and then iterates through the data, appending each value as a new line in the document usingInsertAfter.Finally, the code activates the new text document using
Activate.Now, go back to the Job Request Sheet and add a timer event by right-clicking on the sheet tab and selecting "View Code". In the VBA Editor, select "Worksheet" from the dropdown at the top left and "Timer" from the dropdown at the top right. Then, paste the following code:
Private Sub Worksheet_Timer() Call SubmitFormAndCopy Me.TimerInterval = 0 ' Stop the timer after one execution End SubThis code sets up a timer that calls the
SubmitFormAndCopyfunction and stops the timer after one execution by setting theTimerIntervalproperty to 0.Now, go back to the Job Request Sheet and right-click on the form button. Select "Assign Macro" and select the
SubmitFormAndCopymacro from the list.When you click the form button, the code will execute and open a new text document with the copied values. The timer event will automatically start after the code execution and will execute the same code after a certain interval (depending on the
TimerIntervalproperty value). - User
In an excel Sheet Job Request When I choose a value from a list using a form button on the Job Request Sheet I want the sheet to calculate, then 4 seconds later I want to copy all the values of cells with values fom column J of the sheet named in I2 of Job Request, and paste the copied values into a new text document line by line and have focus, activate the text document
- Assistant
To accomplish this in Excel, you can use VBA code and a timer event.
First, create your form button on the Job Request Sheet and go to the VBA Editor by pressing Alt+F11. Add a new module and paste the following code:
Public Sub SubmitFormAndCopy() ' Get the selected value from the list Dim selectedValue As String selectedValue = Range("B2").Value ' Change to your cell location ' Perform calculations based on the selected value ' Replace this with your own calculation code ' Wait for 4 seconds Application.Wait Now + TimeValue("0:00:04") ' Get the sheet name from I2 Dim sheetName As String sheetName = Range("I2").Value ' Get the data from column J of the specified sheet Dim data As Variant data = Worksheets(sheetName).Range("J:J").Value ' Create a new text document Dim doc As Object Set doc = CreateObject("Word.Document") doc.Application.Visible = True ' Iterate through the data and append each value as a new line in the document Dim i As Long For i = 1 To UBound(data) If Not IsEmpty(data(i, 1)) Then ' Exclude empty cells doc.Content.InsertAfter data(i, 1) & vbNewLine ' Add a newline character End If Next i ' Activate the text document doc.Activate End SubThis code is similar to the Google Apps Script code, but with some differences in syntax. It first gets the selected value from the form button and performs any necessary calculations, and then waits for 4 seconds using the
Application.Waitmethod.Next, it retrieves the sheet name from cell I2 and gets all the data from column J of that sheet using
Worksheets.Range().Value.The code creates a new text document using
CreateObject("Word.Document")and then iterates through the data, appending each value as a new line in the document usingInsertAfter.Finally, the code activates the new text document using
Activate.Now, go back to the Job Request Sheet and add a timer event by right-clicking on the sheet tab and selecting "View Code". In the VBA Editor, select "Worksheet" from the dropdown at the top left and "Timer" from the dropdown at the top right. Then, paste the following code:
Private Sub Worksheet_Timer() Call SubmitFormAndCopy Me.TimerInterval = 0 ' Stop the timer after one execution End SubThis code sets up a timer that calls the
SubmitFormAndCopyfunction and stops the timer after one execution by setting theTimerIntervalproperty to 0.Now, go back to the Job Request Sheet and right-click on the form button. Select "Assign Macro" and select the
SubmitFormAndCopymacro from the list.When you click the form button, the code will execute and open a new text document with the copied values. The timer event will automatically start after the code execution and will execute the same code after a certain interval (depending on the
TimerIntervalproperty value).Note: You may need to enable the Microsoft Word Object Library to use
CreateObject("Word.Document"). To do this, go to Tools -> References in the VBA Editor and select "Microsoft Word Object Library".
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.