Reputation: 1
How do I make an Excel script "go to" a specific sheet after copying data from an initial sheet? (I.e. I can record a script to copy data from Sheet1 and paste to specific columns on Sheet2 easily but I want the user to see Sheet2 once this is complete)
I have just started using Excel scripts for our small company. The company uses an Excel document on a shared OneDrive account to handle booking in jobs/invoicing. The system works but is limited. I created an Excel system using VBA that had pages to enter information (such as a booking in page, a quote calculation page etc) and create invoices at the click of a button (instead of duplicating a blank invoice, copying a row from the main sheet onto row two of the blank invoice, adding parts and pricing, then editing a few cells in a row near the bottom which is then copied to another sheet for record-keeping). The problem was that the macros can't run on Excel for the web & some users are remote/mobile, so I upgraded my license to access scripts instead so everyone could update the sheet as and when required and still use buttons to carry out all required functions.
My programming knowledge is extremely limited - I could edit VBA code relatively easily after recording my actions, and felt it was quite intuitive, however I am struggling a bit more with this in TypeScript. I could always find huge swathes of VBA help on forums with quick Google searches for similar issues and adapt the answers to suit my needs, however there isn't much out there on Excel scripts with TypeScript yet.
Often the basic scripts I have created are to move information from an initial sheet to a register. For example, an initial call-handling sheet that the user inputs the call information (who is calling, phone number, name, requirements etc), the user then clicks a button to store the call information on the call register. All users can view the call register, for example if a customer called back later and I answered, I can see what information my colleague discussed with them earlier.
At the moment I want to move information from an initial sheet to a secondary sheet depending on what the user wants to do. I have one user entered field on the initial sheet (a unique identifier) that looks up information from a customer database, a call database and a bookings database, then a selection of buttons depending on what the user wants to do, for example book in a job, update customer information etc. (Likely to be 5-6 buttons) If the user wants to book in a job, I want that button to take all the information (the unique identifier and the various lookup values from the different databases) and put it onto another page, which will contain fields to specify job details (parts required, pricing, availability etc). I have no problem creating a script to move the information, however when I run it, the user stays on the initial sheet. I want the user to be automatically taken to the page the script copied the information to, so they can fill out any subsequent information required.
How can I write the code to go to the page in a way that I can just copy-paste it into the current script?
Upvotes: 0
Views: 312
Reputation: 251
You can use the worksheet.activate API.
workbook.getWorksheet("Sheet2").activate();
Upvotes: 1