convert macro into office scripts

ZoeC

New Member
Joined
Sep 22, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I've been using a very simple macro in excel to tally the number of enquiries we answer on certain topics. I have a range of buttons labelled 'Access Query', 'Directional Query', 'IT Query' etc. each using a version of this macro;

Sub Button1_Click()
Range("A1") = Range("A1") + 1
End Sub

so that every time I answer an enquiry, I click the corresponding button and the cell increases by one.

It would now be useful to have multiple people access the sheet at the same time so we're moving to excel online which won't run the macro so I'm trying to work out how to use office scripts to do the same thing.

so far I've got to;

function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getWorksheet("22.09.23");
sheet.getRange("A1").setValue("=SUM(A1+1)")}


but A1 always equals 0 - it's not +1ing.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi, welcome to the forum!

You could try like this:
JavaScript:
function main(workbook: ExcelScript.Workbook) {
  let sheet = workbook.getWorksheet("22.09.23");
  sheet.getRange("A1").setValue(Number(sheet.getRange("A1").getValue()) + 1);
}
 
Upvote 0
Solution

Forum statistics

Threads
1,223,872
Messages
6,175,104
Members
452,613
Latest member
amorehouse

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top