VBA to filter between two amount I put in a popup box?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I want to create a macro that asks the peson to insert tow amounts into a messagebox or any kind of popup box then filters by this?

I know how to use userforms so that would do me fine.

I currently use this

Code:
Sub Filterby1()
Sheets("Master").Unprotect 'Password:="august"
    sDate = Sheets("Master").Range("F14")
    EDate = Sheets("Master").Range("F15")
    Sheets("Master").Range("C19:BD19").AutoFilter
    Sheets("Master").Range("C19:BD2504").AutoFilter Field:=1, Criteria1:=">=" & sDate, Operator:=xlAnd, Criteria2:="<=" & EDate
Sheets("Master").Protect 'Password:="august"
End Sub

so the message box can put the values into F14 & F15 or just use them

please help if you can

Thanks

Tony
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
i use a pseudo Query to filter my results.
my date field is G
and a marker is H (this flags the record if condition is true)
then filter the results.

adjust your columns as needed.


Code:
Public Sub FilterRecs()
Dim sDate As Date, eDate As Date, vDate
Dim iRows As Long
Const kDTE = 6
Const kMARK = 7


'sDate = "11/1/2018"
'eDate = "12/31/2018"


Sheets("Master").Unprotect 'Password:="august"
    sDate = Sheets("Master").Range("F14")
    EDate = Sheets("Master").Range("F15")
    Sheets("Master").Range("C19:BD19").AutoFilter
    Sheets("Master").Range("C19:BD2504").AutoFilter Field:=1, Criteria1:=">=" & sDate, Operator:=xlAnd, Criteria2:="<=" & EDate
Sheets("Master").Protect 'Password:="august"


'no filter here


   'clean slate
Range("A1").Select
iRows = ActiveSheet.UsedRange.Rows.Count
Columns("h:h").Clear
Range("H1").Value = "MARK"


   'loop thru the recs to find our matches
Range("A2").Select
While ActiveCell.Value <> ""
       'CHECK date condition
   vDate = ActiveCell.Offset(0, kDTE).Value
   If vDate >= sDate And vDate <= eDate Then
      Debug.Print vDate
      ActiveCell.Offset(0, kMARK).Value = True
   End If
    
    ActiveCell.Offset(1, 0).Select  'next cell
Wend


Selection.AutoFilter
ActiveSheet.Range("$A$1:$h$" & iRows).AutoFilter Field:=(kMARK + 1), Criteria1:="<>"
MsgBox "Done"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,121
Members
452,545
Latest member
boybenqn

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