Forum Discussion

Azeddin_Margani's avatar
Azeddin_Margani
Contributor
8 years ago
Solved

To write test Results into a column in excel

Hi,   I am getting test data from an excel file and wish to write the result for a particular test into a specific column called "CardNumber" on the same row (in the same excel file) . I'm using DD...
  • Colin_McCrae's avatar
    Colin_McCrae
    8 years ago

    Azeddin_Margani wrote:

     

     inputRow = excelMainSheet.UsedRange.Rows.Count;

    excelMainSheet.Range("K" + inputRow).Value =CardNum;

     


    OK. You're not mixing COM and DDT. That's good. :)

     

    As previously explained, the above code is your problem. UsedRange gets the last row. So you are always writing to the last row.

     

    If this is looping through 100 rows of data, I assume you must have it in some sort of loop?

     

    In which case (pseudocode) you want something like:

     

    Loop Start
    
       Do your test and extract the value
       
       Excel.Cells(Loop, Column) = Your_Value
    
    End Loop

     

    Or something like that.

     

    Basically, as shankar_r says, you need to track the row you are on. Which I presume you are (or will be) doing if you're using the same sheet for you input data?

     

    (Incidentally, I've used the "Cells" method in Excel. Which uses a numeric for both Row and Column. You can use Range, but it's really designed for updating multiple cells in one go. But it will work with a single cell value.)