excel - Subscript out of range error in VBA -


i trying import fdf files(can multiple) vba. when run code got subscript out of range error.

i know error suggests worksheet looking not exist don't believe code below defines worksheet name cause of problem?

can have assistance in where, , what, code insert address error? code tried:

sub fdfimport()      dim outsh worksheet     dim fname variant, f integer     fname = application.getopenfilename("fdf file,*.fdf", 1, "select 1 or more files open", , true)      f = 1 ubound(fname)        open fname(f) input #1        while not eof(1)           line input #1, myvar          arr = split(myvar, chr(10))          arr2 = split(arr(4), "/v")           if instr(1, myvar, "(contact)") > 0              set outsh = sheets("contact")             outrow = outsh.cells(rows.count, 1).end(xlup).offset(1, 0).row              = 1 8                 placer = instr(1, arr2(i), ")")                outsh.cells(outrow, i).value = left(arr2(i), placer - 1)              next           else              set outsh = sheets("nocontact")             outrow = outsh.cells(rows.count, 1).end(xlup).offset(1, 0).row              = 1 12                 placer = instr(1, arr2(i), ")")                outsh.cells(outrow, i).value = left(arr2(i), placer - 1)              next           end if        loop        close #1        sheets("contact").cells.replace what:="(", replacement:=""        sheets("nocontact").cells.replace what:="(", replacement:=""     next f  end sub 

this guess based on have posted give try

sub fdfimport()      dim outsh worksheet       dim fname variant, f integer     dim myvar, arr, arr2, outrow, i, placer      fname = application.getopenfilename("fdf file,*.fdf", 1, "select 1 or more files open", , true)      if vartype(fname) = vbboolean         exit sub     end if      f = lbound(fname) ubound(fname)        open fname(f) input #1        while not eof(1)           line input #1, myvar           arr = split(myvar, chr(10))           arr2 = split(arr(4), "/v")           if instr(1, myvar, "(contact)") > 0              set outsh = sheets("contact")             outrow = outsh.cells(rows.count, 1).end(xlup).offset(1, 0).row              = 0 7                 placer = instr(1, arr2(i), ")")                outsh.cells(outrow, i).value = left(arr2(i), placer - 1)              next           else              set outsh = sheets("nocontact")             outrow = outsh.cells(rows.count, 1).end(xlup).offset(1, 0).row              = 0 11                 placer = instr(1, arr2(i), ")")                outsh.cells(outrow, i).value = left(arr2(i), placer - 1)              next           end if        loop        close #1        sheets("contact").cells.replace what:="(", replacement:=""        sheets("nocontact").cells.replace what:="(", replacement:=""     next f  end sub 

when split array 0 based. meaning need loop through array 0 x. when looping arr2 have for = 1 8 guess should for = 0 7 doing same arr have changed answer.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -