problems with macro

royboy531

Board Regular
Joined
Nov 11, 2005
Messages
52
I want to use a macro to open a userform and filter data(which I already have code for) then close the userform and have my filtered data. I don't know code very well and I was trying to record the macro but it wouldn't work. any Ideas
thanks
royboy531
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Userform1.show, Unload Userform1, Userform1.hide, and Unload Me may be of some use to you. "Userform1" is interchangeable with your userform name. Insert YourUserformName.show in a sub to get started. Good luck! Dave
 
Upvote 0
What I didn't mention in my message is that I am extremely new to this and I'm not sure what your message means. Do I add it to the end of the macro that I have attached to the cammand button??? I do appriciate the help.
royboy531
 
Upvote 0
Code:
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
This will show you "Userform1" if you have a command button 1. See the VBA help for hide,unload etc. HTH. Dave
 
Upvote 0
I tried to put the code that you gave me in the command button code enty box under the code I had for the filter but it didn't seem to work right. I used
Code:
Private Sub CommandButton1_Click() 
UserForm1.Show 
End Sub

under my code of

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
    
    'FILTERS
    With Worksheets("Nov2005")
        .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)
        
    End With

not sure where I am going wrong. I went to help and it was kind of confusing and didn't explain very clearly. I appriciate your help.
royboy531
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,104
Members
448,548
Latest member
harryls

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