Inconsistent failures in Excel VBA for automatic row insert -


i using excel sheet track job applications.

i have 2 sheets:
1. first sheet has 1 row each application latest status
2. second sheet has each "state" every application went through eg completed application -> interview scheduled -> job offered (more completed application -> application rejected, digress).

the vb script have this:
1. on first sheet whenever status of row changed, update timestamp.
2. on second sheet, whenever status of row changed in first sheet, create new row in second sheet status ,to status , timestamp.

#1 works flawlessly. seemingly @ random (most of time when update row in middle of sheet) vba crashes "end debug" dialog box when inserting row second sheet

the script below:

dim oval public sub worksheet_selectionchange(byval target range) oval = target.value on error resume next application.enableevents = true end sub   private sub worksheet_change(byval target range) old_value = oval application.enableevents = false if target.column = 5     cells(target.row, 6) =     dim firstemptyrow long      set rngtosearch = worksheets("level 2").range("a:a")     'check first cell isn't empty     if isempty(rngtosearch.cells(1, 1))         firstemptyrow = rngtosearch.cells(1, 1).row     else         set firstblankcell = rngtosearch.findnext(after:=rngtosearch.cells(1, 1))         if not firstblankcell nothing             firstemptyrow = firstblankcell.row         else             'no empty cell in range searched          end if     end if     debug.print firstemptyrow     worksheets("level 2").cells(firstemptyrow, 1) = worksheets("level 1").cells(target.row, 1)     worksheets("level 2").cells(firstemptyrow, 2) = old_value     worksheets("level 2").cells(firstemptyrow, 3) = worksheets("level 1").cells(target.row, 5)     worksheets("level 2").cells(firstemptyrow, 4) =  end if if target.column <> 1 , isempty(worksheets("level 1").cells(target.row, 1))     dim curr_id long     curr_id = worksheets("level 1").cells(target.row - 1, 1)     if worksheets("level 1").cells(target.row - 1) = 1         curr_id = 1     end if     worksheets("level 1").cells(target.row, 1) = curr_id + 1 end if on error resume next  application.enableevents = true end sub 

i tried little bit of debugging , here's got:
firstemptyrow value 0 whenever vba crashes on line worksheets("level 2").cells(firstemptyrow, 1) = worksheets("level 1").cells(target.row, 1)

this tells me thought range search whole column (which must have empty row @ point considering ~200 rows till now) have not done enough vb programming figure out how fix , hoping 1 of folks can me out.

thanks!


Comments

Popular posts from this blog

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -