Auto refresh a macro?

USCguy09

New Member
Joined
Mar 31, 2011
Messages
28
i found a macro where it counts the # of files in a specified directory.
Problem is, when I add/delete files in the directories, the true # isn't reflected in excel unless I double click & enter on the cell containing the formula.
I recorded a macro, titled refresh, that does this for cells D19 - D23.

Is there a way where I can get the refresh macro to just run every X minutes instead of me having to click it every time?

Code:
Sub refresh_files()
'
' refresh_files Macro
'

'
    Range("D19").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D20").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D21").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D22").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D23").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D19").Select
End Sub
2-11.png
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
If you make your countfilesif function volatile it will refresh each time the workbook is calculated. To do that put:

Application.Volatile

at the beginning of the function.
 
Upvote 0
If you make your countfilesif function volatile it will refresh each time the workbook is calculated. To do that put:

Application.Volatile

at the beginning of the function.

thanks but that only refreshes when i manually recalculate it.
i looked into this further and found the Ontime method and Sub Auto_open() function.

seems to be working like how i want it now.

Code:
Sub Auto_Open()
Call auto_refresh
End Sub

Sub auto_refresh()

' execute macros
Range("D19").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D20").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D21").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D22").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D23").Select
    ActiveCell.FormulaR1C1 = "=countfilesif(R[-8]C,R[-8]C[3],FALSE,R[-8]C[5])"
    Range("D19").Select
' submit macro to run again in 1 min
Application.OnTime Now + TimeValue("00:01:00"), "auto_refresh"

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,589
Messages
6,179,744
Members
452,940
Latest member
rootytrip

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