Auto clicking macro button

dp001

New Member
Joined
Mar 6, 2019
Messages
3
Hi

Code:
Sub Button1_Click()
    Range("T23").Select
    Selection.ClearContents
End Sub
Sub test()
    Application.OnTime Now + TimeValue("00:00:10"), "Repeat_VBA"
End Sub

Above is the code I have.

I have created a button which when clicked manually clears the contents in T23, as seen in the top half of the code.

I have written the second half of the code in the hope it will auto click the button every 10 seconds but it doesn't do anything.

Can anyone see what's wrong with this?

Thanks
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
10,210
Welcome to the Board.

Try:

Code:
Sub Button1_Click()
    Range("T23").ClearContents
End Sub
Sub Repeat_VBA()
    Button1_Click
    Application.OnTime Now + TimeValue("00:00:10"), "Repeat_VBA"
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,010
Office Version
  1. 365
Platform
  1. Windows
Cross posted https://www.excelforum.com/excel-fo...7362-auto-click-macro-button.html#post5078295

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
10,210
How are you initiating the second macro? If you just want the first button click to start the process:

Code:
Sub Button1_Click()
    Range("T23").ClearContents
    Application.OnTime Now + TimeValue("00:00:10"), "Button1_Click"
End Sub
How do you plan to end the process? You could monitor a certain cell and if it sees an "x", stop:
Code:
Sub Button1_Click()
    Range("T23").ClearContents
    If Range("T24") = "x" Then Exit Sub
    Application.OnTime Now + TimeValue("00:00:10"), "Button1_Click"
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,108,507
Messages
5,523,310
Members
409,511
Latest member
hitesh222002

This Week's Hot Topics

Top