0

I am working on a google docs sheet, currently trying to automate most of the data entry. I want to do an action if a text is found in a cell.

Have a look at this sheet: https://docs.google.com/spreadsheet/ccc?key=0AlfftUoJOAjCdGp0Z2stbmhncGs0bFE5ZU43dkFLVEE#gid=0

I have those scenarios:

  1. Monthly -> Indicated by number. Pseudo-code: if number.
  2. Quarterly -> Indicated by "Quarter". Pseudo-code: if text contains "Quarter"
  3. Yearly -> Indicated by "Yearly". Pseudo-code: if text contains "Yearly"

How can I check each of the three scenarios in Google docs?

j0k
  • 22,600
  • 28
  • 79
  • 90
Hendrik
  • 4,849
  • 7
  • 46
  • 51
  • 1
    I did not understood what is your problem. Can you please edit your question and re-phrase it? By the way, formulas can be copied down and they will update the references accordingly, do you know that? – Henrique G. Abreu Jul 13 '12 at 13:26
  • Thx + sorry. I tried to made it more clear. does it help? – Hendrik Jul 14 '12 at 23:08
  • Sorry, maybe it's me, but it didn't. I saw now that you question does not have the google-apps-script tag, I'll re-tag it and someone else will probably be able to help you. – Henrique G. Abreu Jul 16 '12 at 00:11

1 Answers1

1

try this:

function foo(){
var range = SpreadsheetApp.openById("your_spreadsheet_id").getSheetByName("Sheet1").getRange("A:A");
var values = range.getValues();
for(var i in values){
  if(values[i][0].match("Monthly")!=null){
     //cell contains "Monthly". Do something 
  } 
  if(values[i][0].match("Quarterly")!=null){
     //cell contains "Quarterly". Do something 
  }
  if(values[i][0].match("Yearly")!=null){
     //cell contains "Yearly". Do something 
  }
}

This will scan all the cells in the A column and call different functions based on their content.

Kuba Orlik
  • 3,360
  • 6
  • 34
  • 49