Excel Office Scripts - This formula will not run automatically does fine manually.

Copper Contributor

Good afternoon, 

I am working on automating a massive data sheet (regenerates every month) and I have gotten everything to work so far except this one step. 

 

After all the automation so far its a single sheet. What I am trying to do is organize each WO by Unit name using this function: 

 

"=IFERROR(INDEX($E$2:$E$10000, SMALL(IF($I$2=$D$2:$D$10000, ROW($E$2:$E$10000)-1,""), ROW()-1)),"")"

 

Which works just fine when typed in and dragged. However when I automate it using the code editor recorder, it always claims to get everything, and then when run on a new workbook (exactly the same copy) it fails. Displaying this error: 

Line 4: Range setFormulaLocal: The argument is invalid or missing or has an incorrect format.

Before Automation:

  UNITLONGUNITNAMEWOHOURS       
  LDR125IS6CA3213DA +LDR1251E+091.167  HDA20YHDA20YHDA20Y  
  LDR125IS6CA3213DA +LDR1251E+091.967    0  
  LDR125IS6CA3213DA +LDR1251E+091.783       
  LDR125IS6CA3213DA +LDR1251E+092.626       
  LDR125IS6CA3213DA +LDR1251E+090.422       
  LDR125IS6CA3213DA +LDR1251E+091.367       
  LDR125IS6CA3213DA +LDR1251E+092.554       
  LDR125IS6CA3213DA +LDR1251E+092.759       
  LDR125IS6CA3213DA +LDR1251E+093.237-       
  LDR125IS6CA3213DA +LDR1251E+093.237       
  LDR125IS6CA3213DA +LDR1251E+093.658       
  LDR125IS6CA3213DA +LDR1251E+093.227-       
  LDR125IS6CA3213DA +LDR1251E+093.227       
  LDR125IS6CA3213DA +LDR1251E+090.36       
  LDR125IS6CA3213DA +LDR1251E+091.286       
  LDR125IS6CA3213DA +LDR1251E+090.644       
  HDA40YT6NJ21O9CBHDA40Y1E+091.421       
  HDA40YT6NJ21O9CBHDA40Y1E+092.605       
  HDA40YT6NJ21O9CBHDA40Y1E+090.251       
  HDA40YT6NJ21O9CBHDA40Y1E+090.163       
  HDA40YT6NJ21O9CBHDA40Y1E+091.003       
  HDA40YT6NJ21O9CBHDA40Y1E+091.334       
  HDA40YT6NJ21O9CBHDA40Y1E+090.743       
  HDA40YT6NJ21O9CBHDA40Y1E+091.848       
  HDA40YT6NJ21O9CBHDA40Y1E+090.83       
  HDA40YT6NJ21O9CBHDA40Y1E+092.939       
  HDA40YT6NJ21O9CBHDA40Y1E+090.527       
  HDA40YT6NJ21O9CBHDA40Y1E+091.012       
  HDA40YT6NJ21O9CBHDA40Y1E+091.085       
  HDA20YM6NB11O9CBHDA20Y1E+090.666       
  HDA20YM6NB11O9CBHDA20Y1E+090.573       
  HDA20YM6NB11O9CBHDA20Y1E+090.473       
  HDA20YM6NB11O9CBHDA20Y1E+090.826       
  HDA20YM6NB11O9CBHDA20Y1E+091.704       
  HDA20YM6NB11O9CBHDA20Y1E+090.09       
  HDA20YM6NB11O9CBHDA20Y1E+091.151       
  HDA20YM6NB11O9CBHDA20Y1E+091.972       
  HDA20YM6NB11O9CBHDA20Y1E+092.732       
  HDA20YM6NB11O9CBHDA20Y1E+090.654       
  HDS60FT6UJ3111CA +HDS60F1E+090.944       
  HDS60FT6UJ3111CA +HDS60F1E+090.51       
  HDS60FT6UJ3111CA +HDS60F1E+090.113       
  HDS60FT6UJ3111CA +HDS60F1E+090.414       
  HDS60FT6UJ3111CA +HDS60F1E+092.417       
  HDS60FT6UJ3111CA +HDS60F1E+093.524       
  HDS60FT6UJ3111CA +HDS60F1E+090.614       
  HDS60FT6UJ3111CA +HDS60F1E+091.475       
  HDS60FT6UJ3111CA +HDS60F1E+091.049       
  HDS60FT6UJ3111CA +HDS60F1E+090.806       
  HDS60FT6UJ3111CA +HDS60F1E+091.361       
  HDI130FT6UD3326CA +HDI1301E+093.25       
  HDI130FT6UD3326CA +HDI1301E+091       
  HDI130FT6UD3326CA +HDI1301E+090.75       
  HDI130FT6UD3326CA +HDI1301E+091.15       
  HDR45IS6CA3214DA +HDR45I1E+091.285       
  HDR45IS6CA3214DA +HDR45I1E+093.5       
  HDR45IS6CA3214DA +HDR45I1E+091.615       
  HDR45IS6CA3214DA +HDR45I1E+093.5       
  HDR45IS6CA3214DA +HDR45I1E+091.968       
  HDR45IS6CA3214DA +HDR45I1E+090.766       
  HDR45IS6CA3214DA +HDR45I1E+090.003       
  HDR45IS6CA3214DA +HDR45I1E+090.98       
  HDR45IS6CA3214DA +HDR45I1E+092.007       
  HDR45IS6CA3214DA +HDR45I1E+091.845       
  HDR45IS6CA3214DA +HDR45I1E+093.497       
  HDR45IS6CA3214DA +HDR45I1E+090.149       
  HDR45IS6CA3214DA +HDR45I1E+090.1       
  HDR45IS6CA3214DA +HDR45I1E+090.872       
  HDR45IS6CA3214DA +HDR45I1E+090.9       
  HDR45IS6CA3214DA +HDR45I1E+091.355       
  HDA20YM6NB11O9CBHDA20Y1E+090.754       
  HDA20YM6NB11O9CBHDA20Y1E+090.637       
  HDA20YM6NB11O9CBHDA20Y1E+091.715       
  HDA20YM6NB11O9CBHDA20Y1E+093.098       
  HDA20YM6NB11O9CBHDA20Y1E+090.746       
  HDA20YM6NB11O9CBHDA20Y1E+090.772       
  HDA20YM6NB11O9CBHDA20Y1E+091.488       
  HDA20YM6NB11O9CBHDA20Y1E+091.685       
  HDA20YM6NB11O9CBHDA20Y1E+091.456       
  HDA20YM6NB11O9CBHDA20Y1E+092.743       
  HDA20YM6NB11O9CBHDA20Y1E+091.167       
  HDA20YM6NB11O9CBHDA20Y1E+090.191       
  HDA20YM6NB11O9CBHDA20Y1E+090.573       
  HDA20YM6NB11O9CBHDA20Y1E+092.941       
  HDA20YM6NB11O9CBHDA20Y1E+091.937       
  HDA20YM6NB11O9CBHDA20Y1E+090.904       
  HDA20YM6NB11O9CBHDA20Y1E+090.984       
  HDA20YM6NB11O9CBHDA20Y1E+090.108       
  HDA20YM6NB11O9CBHDA20Y1E+092.624       
  HDA20YM6NB11O9CBHDA20Y1E+090.243       
  HDA20YM6NB11O9CBHDA20Y1E+091.256       
  HDA20YM6NB11O9CBHDA20Y1E+091.917       
  HDA20YM6NB11O9CBHDA20Y1E+090.646       
  HDA20YM6NB11O9CBHDA20Y1E+092.776       
  HDA20YM6NB11O9CBHDA20Y1E+092.647       
  HDA20YM6NB11O9CBHDA20Y1E+090.307       
  HDA20YM6NB11O9CBHDA20Y1E+090.115       
  HDA20YM6NB11O9CBHDA20Y1E+090.271       
  HDA20YM6NB11O9CBHDA20Y1E+092.565       
  HDA20YM6NB11O9CBHDA20Y1E+090.988       
  HDA20YM6NB11O9CBHDA20Y1E+090.821       
  HDA20YM6NB11O9CBHDA20Y1E+090.014       
  HDA20YM6NB11O9CBHDA20Y1E+090.061       
  HDA20YM6NB11O9CBHDA20Y1E+090.831       
  HDA20YM6NB11O9CBHDA20Y1E+090.641       
  HDA20YM6NB11O9CBHDA20Y1E+094.417       
  HDA20YM6NB11O9CBHDA20Y1E+092.02       
  HDA20YM6NB11O9CBHDA20Y1E+091.045       
  HDA20YM6NB11O9CBHDA20Y1E+093.151       
  HDA20YM6NB11O9CBHDA20Y1E+091       
  HDA20YM6NB11O9CBHDA20Y1E+090.308       
  HDA20YM6NB11O9CBHDA20Y1E+090.793       
  HDA20YM6NB11O9CBHDA20Y1E+090.395       
  HDA20YM6NB11O9CBHDA20Y1E+090.912       
  HDA20YM6NB11O9CBHDA20Y1E+090.587       
  HDR45IS6CA3214DA +HDR45I1E+090.734       
  HDR45IS6CA3214DA +HDR45I1E+091.418       
  HDR45IS6CA3214DA +HDR45I1E+090.597       
  HDR45IS6CA3214DA +HDR45I1E+090.715       
  HDR45IS6CA3214DA +HDR45I1E+090.593       
  HDR45IS6CA3214DA +HDR45I1E+093.476       
  HDR45IS6CA3214DA +HDR45I1E+093.119       
  HDR45IS6CA3214DA +HDR45I1E+091.137       
  HDR45IS6CA3214DA +HDR45I1E+092.701       
  HDR45IS6CA3214DA +HDR45I1E+091.822       
  HDR45IS6CA3214DA +HDR45I1E+090.696       
  HDR45IS6CA3214DA +HDR45I1E+093.583       
  HDR45IS6CA3214DA +HDR45I1E+093.5       
  HDR45IS6CA3214DA +HDR45I1E+090.594       
  HDR45IS6CA3214DA +HDR45I1E+090.605       
  HDR45IS6CA3214DA +HDR45I1E+092.192       
  HDR45IS6CA3214DA +HDR45I1E+090.946       
  HDR45IS6CA3214DA +HDR45I1E+091.233       
  HDR45IS6CA3214DA +HDR45I1E+093.713       
  HDR45IS6CA3214DA +HDR45I1E+093.701       
  HDR45IS6CA3214DA +HDR45I1E+093.639       
  HDR45IS6CA3214DA +HDR45I1E+091.567       
  HDR45IS6CA3214DA +HDR45I1E+093.25       
  HDR45IS6CA3214DA +HDR45I1E+091.866       
  HDR45IS6CA3214DA +HDR45I1E+091.492       
  HDR45IS6CA3214DA +HDR45I1E+090.577       
  HDR45IS6CA3214DA +HDR45I1E+091.25       
  HDR45IS6CA3214DA +HDR45I1E+092.25       
  HDR45IS6CA3214DA +HDR45I1E+094.674       
  HDR45IS6CA3214DA +HDR45I1E+094.614       
  HDI160FT6UJ3C26CA +HDI1601E+091.417       
  HDI160FT6UJ3C26CA +HDI1601E+090.986       
  HDR190JS6CA3213DA +HDR1901E+093.16       
  HDR190JS6CA3213DA +HDR1901E+093.113       
  HDR190JS6CA3213DA +HDR1901E+090.358       
  HDR190JS6CA3213DA +HDR1901E+092.403       
  HDR190JS6CA3213DA +HDR1901E+091.965       
  HDR190JS6CA3213DA +HDR1901E+091.381       
  HDR190JS6CA3213DA +HDR1901E+090.847       
  HDR190JS6CA3213DA +HDR1901E+092.2       
  HDR190JS6CA3213DA +HDR1901E+090.437       
  HDR190JS6CA3213DA +HDR1901E+092.648       
  HDR190JS6CA3213DA +HDR1901E+092.853       
  HDR190JS6CA3213DA +HDR1901E+092.04       
  HDR190JS6CA3213DA +HDR1901E+090.863       
  HDR190JS6CA3213DA +HDR1901E+091.252       
  HDR190JS6CA3213DA +HDR1901E+091.775       
  HDR190JS6CA3213DA +HDR1901E+090.357       
  HDR190JS6CA3213DA +HDR1901E+092.059       
  HDR190JS6CA3213DA +HDR1901E+092.05       
  HDR190JS6CA3213DA +HDR1901E+091.329       
  HDR190JS6CA3213DA +HDR1901E+093.787       
  HDR190JS6CA3213DA +HDR1901E+090.613       
  HDR190JS6CA3213DA +HDR1901E+094.221       
  HDR190JS6CA3213DA +HDR1901E+090.744       
  HDR190JS6CA3213DA +HDR1901E+090.545       
  HDR190JS6CA3213DA +HDR1901E+091.208       
  HDR190JS6CA3213DA +HDR1901E+090.573       
  HDR190JS6CA3213DA +HDR1901E+090.25       
  HDR190JS6CA3213DA +HDR1901E+091.25       
  HDR190JS6CA3213DA +HDR1901E+090.98       
  HDR190JS6CA3213DA +HDR1901E+092.041       
  HDR190JS6CA3213DA +HDR1901E+091.745       
  HDR190JS6CA3213DA +HDR1901E+090.433       
  HDR190JS6CA3213DA +HDR1901E+092.027       
  HDR190JS6CA3213DA +HDR1901E+090.781       
  HDR190JS6CA3213DA +HDR1901E+090.161       
  HDR190JS6CA3213DA +HDR1901E+092.529       
  HDR190JS6CA3213DA +HDR1901E+090.593       
  HDR190JS6CA3213DA +HDR1901E+093.369       
  HDR190JS6CA3213DA +HDR1901E+091.029       
  HDR190JS6CA3213DA +HDR1901E+090.772       
  HDR190JS6CA3213DA +HDR1901E+092.22       
  HDR190JS6CA3213DA +HDR1901E+092.438       
  HDR190JS6CA3213DA +HDR1901E+090.75       
  HDR190JS6CA3213DA +HDR1901E+093.336       
  HDR190JS6CA3213DA +HDR1901E+091.022       
  HDR190JS6CA3213DA +HDR1901E+090.316       
  HDR190JS6CA3213DA +HDR1901E+091.69       
  HDR190JS6CA3213DA +HDR1901E+090.511       
  HDR190JS6CA3213DA +HDR1901E+090.728       
  HDR190JS6CA3213DA +HDR1901E+091.296       
  HDR190JS6CA3213DA +HDR1901E+090.333       
             
  HDR190JS6CA3213DA +HDR1901E+090.782       
  HDR190JS6CA3213DA +HDR1901E+094.75       
  HDR190JS6CA3213DA +HDR1901E+093.5       
  HDR190JS6CA3213DA +HDR1901E+090.51       
  HDR190JS6CA3213DA +HDR1901E+092.288       
  HDR190JS6CA3213DA +HDR1901E+092.694       
  HDR190JS6CA3213DA +HDR1901E+091.333       
  HDR190JS6CA3213DA +HDR1901E+090.5       
  HDI130FT6UD3326CA +HDI1301E+090.251       
  HDI130FT6UD3326CA +HDI1301E+094.5       
  HDI130FT6UD3326CA +HDI1301E+090.071       
  HDI130FT6UD3326CA +HDI1301E+091.334       
  HDI130FT6UD3326CA +HDI1301E+091.707       
  HDI130FT6UD3326CA +HDI1301E+093.507       
  HDI130FT6UD3326CA +HDI1301E+095.234       
  HDI130FT6UD3326CA +HDI1301E+095.165       
  HNI100PT6UD3126EA +HNI1001E+091.167       
  HNI100PT6UD3126EA +HNI1001E+091.181       
  HNI100PT6UD3126EA +HNI1001E+097.75       
  HNI100PT6UD3126EA +HNI1001E+094.313-       
  HNI100PT6UD3126EA +HNI1001E+092.029       
  HNI100PT6UD3126EA +HNI1001E+094.313       
  HNI100PT6UD3126EA +HNI1001E+090.683       
  HNI100PT6UD3126EA +HNI1001E+091.5       
  HNI100PT6UD3126EA +HNI1001E+095.5       
  HNI100PT6UD3126EA +HNI1001E+093.333       
  HNI100PT6UD3126EA +HNI1001E+090.503       
  HNI100PT6UD3126EA +HNI1001E+092.298-       
  HNI100PT6UD3126EA +HNI1001E+092.298       
  HNI100PT6UD3126EA +HNI1001E+090.512       
  HNI100PT6UD3126EA +HNI1001E+092.272       
  HNI100PT6UD3126EA +HNI1001E+093.25       
  HNI100PT6UD3126EA +HNI1001E+090.623       
  LNI100PT6UF31O6EA +LNI1001E+090.333       
  LNI100PT6UF31O6EA +LNI1001E+092.667       
  LNI100PT6UF31O6EA +LNI1001E+090.667       
  LNI100PT6UF31O6EA +LNI1001E+090.333       
  LNI100PT6UF31O6EA +LNI1001E+092.333       
  LNI100PT6UF31O6EA +LNI1001E+090.85       
  LNI100PT6UD3126EA +LNI1001E+091.167       
  LNI100PT6UD3126EA +LNI1001E+095.400-       
  LNI100PT6UD3126EA +LNI1001E+090.776       
  LNI100PT6UD3126EA +LNI1001E+095.4       
  LNI100PT6UD3126EA +LNI1001E+091.469       
  LNI100PT6UD3126EA +LNI1001E+091.635       
  LNI100PT6UD3126EA +LNI1001E+091.436       
  LNI100PT6UD3126EA +LNI1001E+091.95       
  LNI100PT6UD3126EA +LNI1001E+091.353       
  LNI100PT6UD3126EA +LNI1001E+090.666       
  LNI100PT6UD3126EA +LNI1001E+092.603       
  LNI100PT6UD3126EA +LNI1001E+090.298       
  LNI100PT6UD3126EA +LNI1001E+092       
  LNI100PT6UD3126EA +LNI1001E+0946.237-       
  LNI100PT6UD3126EA +LNI1001E+0946.237       
  LNI100PT6UD3126EA +LNI1001E+091.75       
  LNI100PT6UD3126EA +LNI1001E+091.75       
  LNI100PT6UD3126EA +LNI1001E+090.733       
  HDI130FT6UJ3C26CA +HDI1301E+094.75       
  HDI130FT6UJ3C26CA +HDI1301E+091.333       
  HDI130FT6UJ3C26CA +HDI1301E+092.567       
  HDI130FT6UJ3C26CA +HDI1301E+093.19       
  HDI130FT6UJ3C26CA +HDI1301E+092.286       
  HDI130FT6UJ3C26CA +HDI1301E+092.48       
  HDI130FT6UJ3C26CA +HDI1301E+090.643-       
  HDI130FT6UJ3C26CA +HDI1301E+090.643       
  HDI130FT6UJ3C26CA +HDI1301E+090.174       
  HDI130FT6UJ3C26CA +HDI1301E+090.65       
  WDI130FT6UD3316CA +WDI1301E+091.326       
  WDI130FT6UD3316CA +WDI1301E+090.124       
  WDI130FT6UD3316CA +WDI1301E+091.547       
  WDI130FT6UD3316CA +WDI1301E+090.029       
  WDI130FT6UD3316CA +WDI1301E+090.4       
  WDI130FT6UD3316CA +WDI1301E+090.962       
  WDI130FT6UD3316CA +WDI1301E+090.661       
  WDI130FT6UD3316CA +WDI1301E+090.058       
  WDI130FT6UD3316CA +WDI1301E+090.224       
  WDI130FT6UD3316CA +WDI1301E+090.818       
  WDI130FT6UD3316CA +WDI1301E+091.498       
  WDI130FT6UD3316CA +WDI1301E+090.94       
  WDI130FT6UD3316CA +WDI1301E+090.96       
  WDI130FT6UD3316CA +WDI1301E+090.488       
  WDI130FT6UD3316CA +WDI1301E+091.221       
  WDI130FT6UD3316CA +WDI1301E+090.044       
  WDI130FT6UD3316CA +WDI1301E+091.291       
  WDI130FT6UD3316CA +WDI1301E+090.511       
  WDI130FT6UD3316CA +WDI1301E+090.525       
  WDI130FT6UD3316CA +WDI1301E+090.379       
  WDI130FT6UD3316CA +WDI1301E+092.686       
  WDI130FT6UD3316CA +WDI1301E+092.53       
  WDI130FT6UD3316CA +WDI1301E+090.444       
  WDI130FT6UD3316CA +WDI1301E+092.511       
  WDI130FT6UD3316CA +WDI1301E+091.017       
  WDI130FT6UD3316CA +WDI1301E+091.5       
  WDI130FT6UD3316CA +WDI1301E+090.5       
  WDI130FT6UD3316CA +WDI1301E+090.08       
  WDI130FT6UD3316CA +WDI1301E+091.335       
  WDI130FT6UD3316CA +WDI1301E+092.622       
  WDI130FT6UD3316CA +WDI1301E+090.197       
  WDI130FT6UD3316CA +WDI1301E+091.595       
             
  WDI130FT6UD3316CA +WDI1301E+090.407       
  WDI130FT6UD3316CA +WDI1301E+091.564       
  WDI130FT6UD3316CA +WDI1301E+092.738       
  WDI130FT6UD3316CA +WDI1301E+090.25       
  WDI130FT6UD3316CA +WDI1301E+091.845       
  WDI130FT6UD3316CA +WDI1301E+091.105       
  WDI130FT6UD3316CA +WDI1301E+090.294       
  WDI130FT6UD3316CA +WDI1301E+091.784       
  WDI130FT6UD3316CA +WDI1301E+091.803       
  WDI130FT6UD3316CA +WDI1301E+091.504       
  WDI130FT6UD3316CA +WDI1301E+092.693       
  WDI130FT6UD3316CA +WDI1301E+090.038       
  WDI130FT6UD3316CA +WDI1301E+092.25       
  WDI130FT6UD3316CA +WDI1301E+090.833       
  WDI130FT6UD3416CA +WDI1301E+090.648       
  WDI130FT6UD3416CA +WDI1301E+090.765       
  WDI130FT6UD3416CA +WDI1301E+090.881       
  WDI130FT6UD3416CA +WDI1301E+091.41       
  WDI130FT6UD3416CA +WDI1301E+092.448       
  WDI130FT6UD3416CA +WDI1301E+092.571       
  WDI130FT6UD3416CA +WDI1301E+091.006       
  WDI130FT6UD3416CA +WDI1301E+091.214       
  WDI130FT6UD3416CA +WDI1301E+092.419       

 

1 Reply

@Anish_Srivastava2002 

Here recorder generates the script with relative references in RC notation, like

function main(workbook: ExcelScript.Workbook) {
	let selectedSheet = workbook.getActiveWorksheet();
	// Set range M2 on selectedSheet
	selectedSheet.getRange("M2").setFormulaLocal("=IFERROR(INDEX(R2C5:R10000C5, SMALL(IF(R2C9=R2C4:R10000C4, ROW(R2C5:R10000C5)-1,\"\"), ROW()-1)),\"\")");
	// Auto fill range
	selectedSheet.getRange("M2").autoFill("M2:M14", ExcelScript.AutoFillType.fillDefault);
}

Thus wrong range reference appears. Correct in the code formula manually, like

function main(workbook: ExcelScript.Workbook) {
	let selectedSheet = workbook.getActiveWorksheet();
	// Set range M2 on selectedSheet
	selectedSheet.getRange("M2").setFormulaLocal("=IFERROR(INDEX($E$2:$E10000, SMALL(IF($I2=$D$2:$D10000, ROW($E$2:$E10000)-1,\"\"), ROW()-1)),\"\")");
	// Auto fill range
	selectedSheet.getRange("M2").autoFill("M2:M14", ExcelScript.AutoFillType.fillDefault);
}

it shall work. At least in that part.