Count of how many times a macro is ran Today

SeliM

New Member
Joined
Aug 10, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Good morning,
Could you advise if it possible to create a macro counter that records how many times a macro is ran on a given day pls.

I have tried to adjust the following to no avail:
"Range("A1").Value = Range("A1").Value + 1" which i found on the web.

Your advice would be much appreciated.

geoff
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
a macro counter that records how many times a macro is ran on a given day
By 'a given day' you mean today?
You need 2 cells, say A1 & B1 in sheet "Sheet1", A1 to store the counter and B1 to store today's date.
In the said macro, say "this_macro", put his code:

VBA Code:
Sub this_macro()
With Sheets("Sheet1") 'adjust the sheet name
    If .Range("B1") <> Date Then
       .Range("B1") = Date
       .Range("A1") = 0
    End If
    .Range("A1") = .Range("A1") + 1
End With
'... rest of your code
End Sub

basically, in every new day you need to reset the counter to 0.
 
Upvote 0
Solution
Good morning Akuini
Many thanks for your advice.
I have been able to replicate the code to count how many times the code itself is ran
I've met a problem when including a simple test code with an error 1004 suggesting I've already used a application defined or object defined which has stumped me!
The code I've used to understand how it all works is below:
Sub count()
'To count how many times the Data entry is ran
Sheets("Sheet2").Select
With Sheets("Sheet2")
If .Range("B1") <> Date Then
.Range("B1") = Date
.Range("A1") = 0
End If
.Range("A1") = Range("A1") + 1
End With

'data sheet (sheet1) selected
Sheets("Sheet1").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = "1"
Range("B3").Select
ActiveCell.FormulaR1C1 = "2"
Range("B4").Select
ActiveCell.FormulaR1C1 = "3"
Range("B5").Select
ActiveCell.FormulaR1C1 = "4"
Range("B6").Select

End Sub

Your advice would be most appreciated
Geoff
 
Upvote 0
I tried your code & and it worked without any error.
Did you try it on a clean workbook (with only sheet1 & sheet2)?
 
Upvote 0
Hi Akuini
yes, i did use a fresh workbook with only 2 worksheets.
Im using 365

I thought I'd save as an .xlsm and see if it worked - to no avail; however, the error message seemed to change.
Now says: "X 400"
1718330628727.png

Maybe it my machine!
 
Upvote 0
Hi Akuini
sorry to be a nuisance with this!
I tried another pc to no avail
I'm wondering if it does not like "Date " when i add the rest of script?

It works fine without additional script.

R
Geoff
 
Upvote 0
In which line the code stopped when you ran the code?
 
Upvote 0
Good morning

I've used the F8 key to step through the code

Its seems that the following is the hiccup (although the code works as a separate macro)

Line
ActiveCell.FormulaR1C1 = "1"

Geoff
 
Upvote 0
Hi Akuini
I have rewritten the entire script, and it functions now!!

I cannot see one letter different - strange.

But many thanks for your support

R

Geoff
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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