reset or empty a userform

royboy531

Board Regular
Joined
Nov 11, 2005
Messages
52
In my macro I have a userform to filter data. sometimes after I use the macro and then run it later the previously entered data will show back up in the userform. what can i put in my code to clear the data after it filters???
thanks
 
I put it right before "userform1.hide" and ran it a few time and it seemed to work. when I would run it before It wouldn't always come back up with the info still in it. I did use "unload userform1".
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
my experience:
"Unload Me" is just fine when used within the userform code.
advantages of this syntax:
1.you can change the name of the userform without having to edit your code.
2.you know at a glance that it's the form itself and not another you are manipulating

depending of your goal, I think you could also use
Code:
       tbstartdate = ""
       Me.Hide
unloading has the advantage of clearing memory, but the userform will have to be loaded each time again, which can be rather annoying when there are much data to load
Code:
Private Sub btnFilter_Click() 
...
        .Range("a1:p1").AutoFilter Field:=1, Criteria1:=(">=" & startDate), _ 
            Operator:=xlAnd, Criteria2:=("<=" & startDate) 
       tbstartdate = ""
       Me.Hide
        Range("A1:P" & Cells(Rows.Count, "A").End(xlUp).Row).Copy 
...

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top