A
A
Anoriella2019-02-04 17:14:55
Google Sheets
Anoriella, 2019-02-04 17:14:55

How to write a macro that activates another macro, depending on a condition?

Google spreadsheets!
There is one cell, which is a drop-down list with 10 items.
Each item has a pre-recorded macro.
One button is required, which will activate a ready-made macro, which corresponds to its own item.
For example:
If cell a1=1, then activate macro1;
Otherwise, if cell a1=2, then activate macro2;
Otherwise, if cell a1=3, then activate macro3...
And so on.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pychev Anatoly, 2019-02-04
@Anoriella

A macro is a procedure
called from code as usual.

sub MyGlavniyMacros()
   select case ActiveSheet.range("A1").value
      case 1: call MySlaveMacros1()
      case 2: call MySlaveMacros2()
      case else : call MySlaveMacrosDefault()
   end select
end sub

the last case else - means to execute for all options not listed above

A
Alexander Ivanov, 2019-02-04
@oshliaer

You can use the switch statement

function oneButtonMacros() {
  switch (SpreadsheetApp.getRange('Sheet1!A1').getValue()) {
    case 1:
      macros1();
      break;
    case 2:
      macros2();
      break;
    case 3:
      macros3();
      break;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question