excel - Error 13 with Dropdown list Audit Log -


i'm trying audit log report. 1 of things report status section can selected through drop down list. here code.

option explicit dim previousvalue variant      private sub worksheet_change(byval target range)         if not intersect(target, range("d2")) nothing         range("e" & target.row & ":f" & target.row).clearcontents         if range("d2").value = "i/c"         range("e" & target.row).locked = true         range("e" & target.row & ":f" & target.row).clearcontents         else         range("e" & target.row).locked = false         end if      end if      if not intersect(target, range("d3")) nothing          range("e" & target.row & ":f" & target.row).clearcontents     end if     if not intersect(target, range("d4")) nothing         range("e" & target.row & ":f" & target.row).clearcontents     end if     if not intersect(target, range("d5")) nothing          range("e" & target.row & ":f" & target.row).clearcontents     end if      sheets("gc-01 history log").cells(1, 1).value = "date"     sheets("gc-01 history log").cells(1, 2).value = "equipment"     sheets("gc-01 history log").cells(1, 3).value = "old status"     sheets("gc-01 history log").cells(1, 4).value = "new status"     sheets("gc-01 history log").cells(1, 5).value = "old reason"     sheets("gc-01 history log").cells(1, 6).value = "new reason"     sheets("gc-01 history log").cells(1, 7).value = "old action"     sheets("gc-01 history log").cells(1, 8).value = "new action"      if target.value <> previousvalue    sheets("gc-01 history log").cells(65000, 1).end(xlup).offset(1, 0).value =    sheets("gc-01 history log").cells(65000, 2).end(xlup).offset(1, 0).value = range(target.address).offset(0, -1)    sheets("gc-01 history log").cells(65000, 3).end(xlup).offset(1, 0).value = target.cells(target.row, 1)    sheets("gc-01 history log").cells(65000, 4).end(xlup).offset(1, 0).value = target.value  end if end sub  private sub worksheet_selectionchange(byval target range) previousvalue = target.value  end sub 

the problem when try change status through drop down menu. error 13 gets thrown. have no idea on how deal this.

edit:- on debug shows error if "target.value <> previousvalue then"

please help

two things:

first:

private sub worksheet_selectionchange(byval target range)     previousvalue = target.value end sub 

only works if change selection. might cause previousvalue empty.

second , more important:

you want declare previousvalue public, else cannot use in both subroutines.

option explicit public previousvalue variant ... 

is want.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -