For Each Loop

MattNewby

Board Regular
Joined
Dec 15, 2009
Messages
155
Hi,

What I am trying to do will take a bit of explaining. I have a random word generator that produces a new word every time F9 is pressed.

I am trying to make it so that F9 is automatically pressed at a user defined interval, but I can not get it to work.

My code is as follows:

Sub Test()

Set A = Sheet1.Range("G13")
Set Y = Sheet1.Range("G12")
Set X = (Now + TimeValue("0:00:Y"))

For Each i In A

If i = "Go" Then

Application.Wait X
SendKeys "F9"

End If

Next i

End Sub

Essentially my logic, planned action is as follows:

*Start the macro
*Cell G13 is the on off switch
*Cell G12 is the number of seconds delay that I want
* For each loop sends the F9 command ad given time interval.


I can't get this to work. If anyone can help it will be greatly appreciated.

Matt:eek:
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try changing this
Set X = (Now + TimeValue("0:00:Y"))

to this
X = Now + TimeSerial(0,0,Y)
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

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