vb.net - Loop through all cells in Range using Interop -


i want loop through cells in range.

dim rngtop, rngall excel.range 'set cell rngtop = directcast(_sheet.cells(1, 2), excel.range) 'set range top cell last cell in cells column rngall = rngtop.end(excel.xldirection.xldown)      each cell excel.range in rngall         if cell.value2 = "x"             'do stuff         end if     next 

cell.value underlined , gives me compil error cell.value2 object , cannot use operator (= in case) on it. me task accomplished? value2 should not object.

i tried:

    dim cell excel.range = nothing     dim integer     = 1 rngall.rows.count         if directcast(rngall.cells(i, 5), excel.range).value2 = "x"         'do stuff         end if     next 

but have same problem above.

i guess have solution. problem here vb doesnt know type value2 deliver delivers object. why code give message =-operator cannot applied. using

if cstr(cell.value2) = "x" ... 

works perfect. best write function check valuetype every possible type , convert it.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -