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
 

royboy531

Board Regular
Joined
Nov 11, 2005
Messages
52
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".
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,393
Messages
5,601,403
Members
414,449
Latest member
Pashtun

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
Top