arrays - why does the code below cause excel to crash? -


intro , issue:

loop through columns of activesheet, if there's title ask user proceed in redimensioning array, , changing value.

it keeps crashing excel after commenting out part array filled. please give me notices , opinions on issue.

about code:

this seed of vba script rearrange column different sheets depending on values in array created, each column found in activesheet represents correct order of columns saved in array , used fix order of columns in specific sheet.

i should mention there not many rows in activesheet arrays 100-200 elements long of text can long 10 letters.

 sub deletecolumns()             dim polyarr(), pointarr(), linearr(), autotitle string             dim crnttitle variant             dim crntrow, crntclmn, lastrow, lastclmn long             set wizard = activesheet      wizard             lastclmn = .cells(1, .columns.count).end(xltoleft).column             lastrow = .range("a" & .rows.count).end(xlup).row              crntclmn = 1 lastclmn                 if len(str(.cells(1,crntclmn).value)) <> 0                     msg1 = msgbox("column index of '" & str(.cells(1,crntclmn).value) & "' . wish proceed?", vbyesno, "confirmation")                         if msg1 = vbyes                             'redim polyarr(int(lastrow - 1))                             'polyarr = .range("c2:c" & lastrow).value                         end if                     end if                 next crntclmn             end              'for each crntclmn in clmnarr                   each crntrow in polyarr()                     msgbox (cstr(crntrow))                 next crntrow              'next crntclmn         end sub   **edit**:  cause of crash       msg1 = msgbox("column index of '" & str(.cells(crntclmn, 1).value) & "' . wish proceed?", vbyesno, "confirmation")                             if msg1 = vbyes                             end if  removed asking user part making code this:      sub deletecolumns()         on error goto local_err         msgbox ("hi world")         dim polyarr(), autotitle string         dim crnttitle variant         dim crntrow, crntclmn, lastrow, lastclmn long         set wizard = activesheet         msgbox ("hiwirld")         wizard             lastclmn = .cells(1, .columns.count).end(xltoleft).column             lastrow = .range("a" & .rows.count).end(xlup).row        msgbox ("hiwrld" & str(lastclmn) & str(lastrow))             crntclmn = 1 lastclmn                 msgbox ("hidon" & str(crntclmn))                 if len(.cells(crntclmn, 1).value) <> 0                  msgbox ("hidonduck" & str(crntclmn))                     'msg1 = msgbox("column index of '" & str(.cells(crntclmn, 1).value) & "' . wish proceed?", vbyesno, "confirmation")                     'if msg1 = vbyes                         redim polyarr(int(lastrow - 1))                         polyarr = .range("c2:c" & lastrow).value     1                'end if                 end if             next crntclmn         end          'for each crntclmn in clmnarr               'for each crntrow in polyarr()                 'msgbox (cstr(crntrow))             'next crntrow          'next crntclmn      local_exit:         exit sub      local_err:         msgbox ex & " " & err.description ' use ctrl-break         resume local_exit         resume ' set next statement here goto line in error     end sub 

and works now, still why cant run msgbox in there?

not answer long comment...

use , error handler:

sub deletecolumns() on error goto local_err  '    <your code>  local_exit:     exit sub  local_err:     msgbox ex & " " & err.description ' use ctrl-break     resume local_exit     resume ' set next statement here goto line in error end sub 

run code see error. use ctrl-break go ide , set next statement resume.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -