Macro to add formula if cell in column equals X

qrtback10

New Member
Joined
Jan 19, 2015
Messages
20
(RE-POSTING DUE TO POOR FORMATTING ON ORIGINAL THREAD)

Hey guys, I have the script below
sort of working. It's posting the formula like it should if column 'K' = "PENDING" and column 'R' = "". No problems so far. The issue that I'm having is that when it posts the formulas, it posts the exact formula that's in the script. I've ran others (and mistakenly assumed that this would) where the formula starts at H2+G2 but if the criteria to match is in row 11, it would go to H11 + G11. In my case now it doesn't do that. I need it to. Any matches it finds, it puts the formula 'H2+G2' but I need the formula numbers to match the row number the function is ran in. Hopefully that makes sense.

This is what I currently have:

Code:
function fillColB() {  
var s = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = SpreadsheetApp.getActive().getSheetByName('Locate');
  var data = sheet.getDataRange().getValues();
  var data_len = data.length;
  for(var i=0; i<data_len; i++)="" {
<data_len; i++) {
    if(data[i][17] == "") {
    if(data[i][10] == "PENDING") {
      var cell = sheet.getRange(i+1,12).setFormula('H2+G2');
      sheet.getRange(i+1,13).setFormula('=C2+M2');
      }
    }
  }

}
</data_len;>
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,216,172
Messages
6,129,289
Members
449,498
Latest member
Lee_ray

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