Search code examples
vb.netexcelcominteropcell

How to edit cell value in VB.net - Using .Interop.Excel


This is a simple question. I have this code:

 CurrentRow = 3
 MyColumn = 2
 CurrentCell = (CurrentRow & "," & MyColumn)
 WorkingSheet.Cells(CurrentCell).value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)

I thought that this would place the data on the 'WorkingSheet' in the position "B3" but it places the data in the cell "AF1".

Why is this?

Thanks,

Josh


Solution

  • Cell is not expected to be used as you are using it; you have to input the row and column indices (as integers) separated by a comma. Thus the right code is:

    WorkingSheet.Cells(CurrentRow, MyColumn).Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)
    

    Another alternative you have is using Range. Example:

    WorkingSheet.Range("B3").Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)