Looping through Excel in an ActiveX DTS Package - Can anyone please help?

  • Hello all,

    thank you for taking the time in reading the below. 

    Basically, I've got an Excel Spreadsheet which I can quite happily open and update.  However, one of my requirements is that I need to be able to loop through each cell update the value (providing the contents meets a predefined value).

    However, I'm having real trouble looping through each and every cell.  I've written a for loop to go through the cells of interest, but it appears using the looping variable doesn't work.  For example, the below fails:

    Doesn't work with an "Unknown runtime error line 66"  Line 66 being the "Excel_WorkSheet.Cells(iRow,iCol) = "Some Value"" below:

    Dim iRow

    Dim iCol

    For iRow = 0 To 1

        For iCol = 0 To 1

            Excel_WorkSheet.Cells(iRow,iCol) = "Some Value"

        Next

    Next

     

    However, if I explicitly state what the row and column values are it works fine, as shown below:

    Dim iRow

    Dim iCol

    For iRow = 0 To 1

        For iCol = 0 To 1

            Excel_WorkSheet.Cells(1,1) = "Some Value"

        Next

    Next

    Is there any kind of type casting I can do to convince the VB Script that iRow and iCol are both Integers?  Or am I doing this in a really stupid way?

    Thanks again for your time.

     


    Ah, give it a reboot, it'll be fine!

    Dan

  • Hello.  I've been really stupid.  I've been looking at this for about 4 hours.  I've had another look after posting this and discovered that I have been deeply affected by my days doing C++.

    That is I have started my looping from 0 instead of 1.  Cell A1 is cell 1,1.  Dur.

    I've changed the looping variable and it is all good.  Thanks for looking anyway, and sorry I've wasted anyone's time.

     


    Ah, give it a reboot, it'll be fine!

    Dan

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply