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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello, royboy531,

to my sense we need some more info
what's the code you use for the userform ?
(initialize or activate event?)
what controls do you want to clear ?

perhaps you feed the userform with some public variables which are not reset ?

kind regards,
Erik
 
Upvote 0
for example if you have textbox named tbStartDate and want the data in it to be dissappeared after clicking a button, on the code you should say

Code:
tbStartDate=""
 
Upvote 0
What happens if you Unload the form (e.g. Unload UserForm1) and then .Show it again? It should clear any previous data. HTH
 
Upvote 0
iggydarsa said:
for example if you have textbox named tbStartDate and want the data in it to be dissappeared after clicking a button, on the code you should say

Code:
tbStartDate=""

there was another question which is probably more important
what's the code you use for the userform ?
(initialize or activate event?)
 
Upvote 0
here is the code I have for the userform
Code:
Private Sub btnFilter_Click()
Dim startDate As String
Dim shift As String
    
    'reads date from the userform
    startDate = tbstartdate.Value 'tbStartDate is the name of the textbox for Starting Date
    shift = tbshift 'tbshift is the name of the textbox for shift
    
    Application.DisplayAlerts = False
    
    'FILTERS
    With Worksheets("sheet1")
        .AutoFilterMode = False
        .Range("a1:p1").AutoFilter
        .Range("a1:p1").AutoFilter Field:=2, Criteria1:=shift
        .Range("a1:p1").AutoFilter Field:=1, Criteria1:=(">=" & startDate), _
            Operator:=xlAnd, Criteria2:=("<=" & startDate)
       UserForm1.Hide
        Range("A1:P" & Cells(Rows.Count, "A").End(xlUp).Row).Copy
    End With

If I used tbstartdate="" where do I put it and do I also need to have one for the tbshift??
 
Upvote 0
There should be "End Sub" you can type it right before that... but i think the real problem might be the Hide comment... If I am mistaken please somebody correct me but Hiding doesnt unloads the form and consumes memory... so I would prefer to use "Unload me" instead of "Userform1.Hide"
 
Upvote 0
what would be the exact code for unload me?? Unload.Me??

I do still want the useform to go away when I click the command button.
 
Upvote 0
Code:
Unload Me

thats it, just space between the two words
 
Upvote 0
Or Unload with the name of the form. When I use Unload Me, I've had some unpredictable results from time to time. Perhaps I just wasn't using it right, when I first started playing with userforms, but I've gotten out of the habit of using Me. Just my $0.02
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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