Question

I'm writing a basic script for the sake of data entry into Excel with Jscript, and I've run into a bit of a roadblock with a strange error (the returned error isn't so much strange, moreso how to go about fixing it).

I'm basically looking for the last free row in my Worksheet by checking the Cells.(i, 8).Value to see if there are two consecutive rows that are empty, break the loop to retain that index i, and perform data entry.

while(!data.AtEndOfStream)//Looping to find the data for the the five digit code found above.
{
var ts = new String(data.ReadLine());
var t=ts.split(",");
    if(search==t[0])
    {
    var i;
        for(i=0; i<wks.UsedRange.Rows.Count; i++)
        {
            if(wks.Cells(i,11).Value==null)
            {
            WScript.StdOut.Writeline("empty at "+i);
            break;
            }
        }
     //Data entry statements etc...
    }
}

When compiling through cmd, I get: Microsoft JScript runtime error: Expected ';' The returned line is on the if(wks.Cells) line, char 4. I'm not sure if this is bad programming on my part, or something I'm completely overlooking...

Was it helpful?

Solution

I'm not completely sure about JScript, but I do know that Cells(0,11) shouldn't work because cells is base 1 (there is no Row 0 in Excel). So, if you try changing your code to:

for(i=1; i<wks.UsedRange.Rows.Count; i++)

I believe it will work. I could be wrong, but it's worth a shot.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top