Create two Buttons that works in mobile in Google Sheets

Wojciech

New Member
Joined
May 13, 2018
Messages
27
Office Version
  1. 2021
Platform
  1. Windows
Hi,
using the website below:
I'm trying to make two check box buttons that will work in an Android application. I copied the code from the video and created two codes for the check box buttons in B3 and C3. The B3 check box is supposed to decrease the value in B2 by 1, and the check box in C3 is supposed to increase the value by 1. Both codes work separately, i.e. when the other one is not present. I would like them to work when entered into Apps Script at the same time. The screenshot below shows the Google sheet view.
form.jpg

Below is the code for both codes:

VBA Code:
function counterMinus () {
  let counterMinusSS=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("dz")
  let counterMinusCell=counterMinusSS.getRange("B1")
  counterMinusCell.setValue(counterMinusCell.getValue()-1)
}

function onEdit(){
  let activeCellMinus = SpreadsheetApp.getActiveSpreadsheet().getActiveCell()
  let reference=activeCellMinus.getA1Notation()
  let sheetName=activeCellMinus.getSheet().getName()
  let activeValueMinus=activeCellMinus.getValue()

  if (reference == "B3" && sheetName == "dz" && activeValueMinus == true) {
    counterMinus();
    activeCellMinus.setValue(false)
  }
}
VBA Code:
function counterPlus () {
  let counterPlusSS=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("dz")
  let counterPlusCell=counterPlusSS.getRange("B1")
  counterPlusCell.setValue(counterPlusCell.getValue()+1)
}

function onEdit(){
  let activeCellPlus = SpreadsheetApp.getActiveSpreadsheet().getActiveCell()
  let referencee=activeCellPlus.getA1Notation()
  let sheetNamee=activeCellPlus.getSheet().getName()
  let activeValuePlus=activeCellPlus.getValue()

  if (referencee == "C3" && sheetNamee == "dz" && activeValuePlus == true) {
    counterPlus();
    activeCellPlus.setValue(false)
  }
}
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Ok, I managed it myself.

VBA Code:
function counterPlus () {
  let counterPlusSS=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("dz")
  let counterPlusCell=counterPlusSS.getRange("b1")
  counterPlusCell.setValue(counterPlusCell.getValue()+1)
}
function counterMinus () {
  let counterMinusSS=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("dz")
  let counterMinusCell=counterMinusSS.getRange("b1")
  counterMinusCell.setValue(counterMinusCell.getValue()-1)
}

function onEdit(){
  let activeCellPlus = SpreadsheetApp.getActiveSpreadsheet().getActiveCell()
  let referencee=activeCellPlus.getA1Notation()
  let sheetNamee=activeCellPlus.getSheet().getName()
  let activeValuePlus=activeCellPlus.getValue()

  if (referencee == "B3" && sheetNamee == "dz" && activeValuePlus == true) {
    counterPlus();
    activeCellPlus.setValue(false)
  }
  if (referencee == "C3" && sheetNamee == "dz" && activeValuePlus == true) {
    counterMinus();
    activeCellPlus.setValue(false)
  }
}
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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