Changing Date in Macro, avoiding constant editting

Taff

Board Regular
Joined
Mar 31, 2004
Messages
151
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Evening All,

i have managed to pull together a working macro, that goes through several worksheets and filters out required data according to specified date.
This is then copied and pasted to a worksheet called Todays Trades.
We then finish up with a autofit of all columns.
The macro works fine, but.......... as you can see i will need to manually edit the macro each time i want a different date.

Is there a way i can do this only once? Or is there a of pointing to somewhere and saying 'use this date'?

Also open to any improvements on the below macro.

VBA Code:
Sub TodaysTrades()
   
     Dim wsToday As Worksheet: Set wsToday = Sheets("Todays Trades")
     Dim wsBTTS As Worksheet: Set wsBTTS = Sheets("BTTS Predict")
     Dim wsLTD As Worksheet: Set wsLTD = Sheets("LTD")
     Dim wsO25 As Worksheet: Set wsO25 = Sheets("O2.5")
     Dim wsCheck As Worksheet: Set wsCheck = Sheets("Check")
     Dim wsLazy As Worksheet: Set wsLazy = Sheets("Lazy")
     Dim wsHomer As Worksheet: Set wsHomer = Sheets("Homer")
     Dim wsMOCS As Worksheet: Set wsMOCS = Sheets("Mocs")
     
Application.ScreenUpdating = False

With wsBTTS.[a4:f2000].CurrentRegion

.AutoFilter 1, "07/02/2021"
wsBTTS.[b4:f2000].SpecialCells(xlCellTypeVisible).Copy wsToday.Range("a" & Rows.Count).End(3)(2)
       
        .AutoFilter
        
         End With
       
With wsLTD.[a4:f4000].CurrentRegion

.AutoFilter 1, "07/02/2021"
wsLTD.[b4:d4000].SpecialCells(xlCellTypeVisible).Copy wsToday.Range("g" & Rows.Count).End(3)(2)
       
        .AutoFilter

End With

With wsO25.[a4:f4000].CurrentRegion

.AutoFilter 1, "07/02/2021"
wsO25.[b4:d4000].SpecialCells(xlCellTypeVisible).Copy wsToday.Range("k" & Rows.Count).End(3)(2)
       
        .AutoFilter

End With

With wsCheck.[a4:f4000].CurrentRegion

.AutoFilter 1, "07/02/2021"
wsCheck.[b4:d4000].SpecialCells(xlCellTypeVisible).Copy wsToday.Range("o" & Rows.Count).End(3)(2)
       
        .AutoFilter

End With

With wsLazy.[a4:f4000].CurrentRegion

.AutoFilter 1, "07/02/2021"
wsLazy.[b4:d4000].SpecialCells(xlCellTypeVisible).Copy wsToday.Range("s" & Rows.Count).End(3)(2)
       
        .AutoFilter

End With

  With wsHomer.[a4:f4000].CurrentRegion

.AutoFilter 1, "07/02/2021"
wsHomer.[b4:d4000].SpecialCells(xlCellTypeVisible).Copy wsToday.Range("w" & Rows.Count).End(3)(2)
       
        .AutoFilter

End With

  With wsMOCS.[a4:f4000].CurrentRegion

.AutoFilter 1, "07/02/2021"
wsMOCS.[b4:d4000].SpecialCells(xlCellTypeVisible).Copy wsToday.Range("aa" & Rows.Count).End(3)(2)
       
        .AutoFilter

End With

Dim x As Integer

For x = 1 To ActiveSheet.UsedRange.Columns.Count

     Columns(x).EntireColumn.AutoFit

Next x
         
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
 
Last edited by a moderator:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try
VBA Code:
.AutoFilter 1, CStr(Date)
 
Upvote 0

Forum statistics

Threads
1,215,706
Messages
6,126,334
Members
449,309
Latest member
kevinsucher

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