VBA Excel Userform Clear Range after vbYesNo -
the code below intended check if cells in given range empty. if not, user asked if want save contents of range. if select "no" contents of range cleared.
dim answer integer if not worksheetfunction.counta(worksheets("temp").range("a1:d101")) = 0 answer = msgbox("save changes account?", vbyesno) if answer = vbyes 'do nothing else worksheets("temp").range("a1:d101").clearcontents end if end if
for reason clear method won't clear anything. have tried first activating sheet. first selecting range. first selecting sheet selecting range. using ".clear" instead of ".clearcontents". adding else statement outer if statement. i've tried selecting range of filled cells. no matter i've done, contents of range stay there until delete manually. else seems work fine. cannot life of me figure out missing code.
any suggestions?
edit: here code entire function:
private sub namebox_change() dim answer integer if not worksheetfunction.counta(worksheets("temp").range("a1:d101")) = 0 answer = msgbox("save changes account?", vbyesno) if answer = vbyes 'do nothing else worksheets("temp").range("a1:d101").clearcontents end if end if me worksheets("temp").cells(1, 1).value = format(date, "mm-dd-yyyy") worksheets("temp").cells(1, 2).value = worksheets("users").cells(.namebox.listindex + 1, 1).value worksheets("temp").cells(1, 3).value = worksheets("users").cells(.namebox.listindex + 1, 6).value worksheets("temp").cells(1, 4).value = worksheets("users").cells(.namebox.listindex + 1, 7).value readlabel.caption = worksheets("temp").cells(102, 3).value spentlabel.caption = worksheets("temp").cells(102, 4).value tospendlabel.caption = worksheets("temp").cells(102, 3).value - worksheets("temp").cells(102, 4).value end end sub
i idiot. function triggered when user selects new name dropdown list. original name being cleared , replaced new name. hadn't realized names had changed. helping @ fresh eyes. leave question in case finds code useful.
Comments
Post a Comment