PDA

View Full Version : Missing before statement



Kninnie
Apr 18th, 2018, 06:21 PM
HELP!!! I am a VBA person and tried to change one of my codes to JavaScript, but I keep getting a "Missing before statement" error. It is driving me crazy. Can someone please help me out and tell me what I am doing wrong? Thank you in advance for any help you can give me!!





function COMPLETE (){
var p, endrow, Services, COMPLETE, oLastRow;
Set Services = ActiveWorkbook.Sheets("Services");
Set return ActiveWorkbook.Sheets("Complete");
endrow = Services.Range("A" + Services.Rows.Count).End(xlUp).Row;
for(p=endrow; p<=2; p++){
if(Services.Cells(p, "P").Value == "99" ){
Set oLastRow = Worksheets("Complete").ListObjects("Complete").ListRows.Add;
Services.Cells(p, "P").EntireRow.Copy;
oLastRow.Range.PasteSpecial xlPasteValues;
Services.Cells(p, "P").EntireRow.Delete;
}
}
}

xelawho
Apr 19th, 2018, 02:02 AM
oLastRow.Range.PasteSpecial xlPasteValues

This line doesn't look right, but can you give us the line number that is throwing the error ( or the line that it refers to)?

xelawho
Apr 19th, 2018, 01:01 PM
second thoughts, I think this might be the culprit:



endrow = Services.Range("ASServices.Rows.Count).End(xlUp).Row;


I think that quote mark shouldn't be there, or if it should it should have a pair somewhere...

deathshadow
Apr 19th, 2018, 02:08 PM
Uhm.. this is JavaSCript right? Since when has there been a "Set" declaration. I'm familiar with var, let, and const... but not set. There's a "Set" object/collection, but that's completely unrelated to what you're trying to do.

Try changing all those "set" to "var". THOUGH... hrmm... No, lose those "set" altogether. Those flat out do not EXIST in JavaScript so I have no idea why you seem to be trying to do that.

Two thirds of that code would NEVER run, some formatting helps make that clearer... See, you have a return WITHOUT a condition:



function COMPLETE (){

var Services = ActiveWorkbook.Sheets("Services");
return ActiveWorkbook.Sheets("Complete");
// NOTHING past this point would ever even run

var // do not allocate/assign var until you need them
endrow = Services.Range("A" + Services.Rows.Count).End(xlUp).Row,
oLastRow;

for (var p = endrow; p <= 2; p++) {
if (Services.Cells(p, "P").Value == "99") {
oLastRow = Worksheets("Complete").ListObjects("Complete").ListRows.Add;
Services.Cells(p, "P").EntireRow.Copy;
oLastRow.Range.PasteSpecial xlPasteValues;
Services.Cells(p, "P").EntireRow.Delete;
}
}

}


So really the endRow, oLastRow, etc, etc, would NEVER even be used.

Depending on the data structure returned by that "ActiveWorkbook" object, that loop may not be the best way of iterating the values either. Reeks of some sort of 'framework' taking simple DOM walking and duplicating the data for no good reason, but that hinges on what all this is supposed to actually do.