VBA, how to edit current code to visual dispaly view

2avrham

Board Regular
Joined
May 12, 2014
Messages
104
Office Version
  1. 365
I have the next VBA code that take to dates and filter all relevant data according to them + move it to new sheet.
I want to improve my code and change it to display view instead of static cells at excel sheet (you may see below how the input data looks now).
<code>Start time filter: 5/20/2018 13:00
End time filter: 5/22/2018 13:00</code>what I hope to see is--> after I click on Macro sign I want to get a new view display, there I want to see 3 filter options: 1. start time (can be always 08:00 and date can be chose from month view dates). 2. End time (as start time) after both of them were set all retrieved data should be according to this time frame. 3. Drop down filter on "Product" column (available in my excel).
My current VBA code:
Code:
<code>Public Sub MyFilter()
    Dim lngStart As Date, lngEnd As Date
    lngStart = Range("b2").Value 'assume this is the start date
    lngEnd = Range("b3").Value 'assume this is the end date
    Range("q:q").AutoFilter field:=1, _
        Criteria1:=">=" & lngStart, _
        Operator:=xlAnd, _
        Criteria2:="<=" & lngEnd


           Range("A1:s3000").Select
    Range("A:A").Activate
    Selection.Copy
    Sheets.Add After:=ActiveSheet
With ActiveSheet
    .Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    .Columns("A:A").EntireColumn.AutoFit
    .Cells.Select
    .Cells.EntireColumn.AutoFit
    .Rows("1:1").Select
    .Application.CutCopyMode = False
    With Selection
         With .Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 15773696
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        .AutoFilter
           Columns("Q:Q").Select
    Selection.NumberFormat = "[$-409]m/d/yy h:mm AM/PM;@"
    End With
    .Columns("A:A").EntireColumn.AutoFit
    .Range("A2").Select
End With</code>
Thanks!!
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,216,438
Messages
6,130,632
Members
449,584
Latest member
c_clark

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