Run Macro automatically

albatross32

New Member
Joined
Feb 17, 2010
Messages
32
I am a VBA novice but want to use;

Private Sub Worksheet_Change(ByVal Target As Range)

In Range S3:S232 all cells are empty.

Formulas within the Worksheet will lead to "1" being entered into one cell at a time in the Range S3:S232.

When that happens I want a two second time delay and then a "1" to be entered in column V of the same row. The existing formulas will not allow another S cell to change until the V cell has changed.

I need the function to remain open so that all the time the Worksheet is activated everytime one of the S cells change the V cell of the same row changes after a two second time delay.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
If Not Intersect(Target, Range("S3:S232")) Is Nothing Then
    If Target.Value = "1" Then
        Application.Wait (Now + TimeValue("0:00:02"))
        Target.Offset(0, 3).Value = "1"
    End If
End If
 
End Sub
 
Upvote 0
Ahh i think i may see the problem. After reading your OP again i noticed that you said you have a formula in column S which puts a value of 1 in column S depending on some set of events. In this situation the macro will not recognize a change in column S if it changes to a value of one. We would need to set the intersect range to the range that makes the change in column S. Does this make sense?
 
Last edited:
Upvote 0
The S column is controlled by a formula in column Q as follows;

=IF($A$9>0,(AND(M3=1,P3=1)),0)

The formula in column S is;

=IF($A$9>0,(IF(Q3=FALSE,"",1)),"")

Any further thoughts?

Thanks for your help thus far in any case!
 
Upvote 0
Are there more formulas in column M and column P that refer elsewhere or is column M & P the columns that you manually enter data. If they are then this will work:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
If Not Intersect(Target, Range("M3:M232")) Is Nothing Then
    If Range("S" & Target.Row) = "1" Then
        Application.Wait (Now + TimeValue("0:00:02"))
        Range("V" & Target.Row).Value = "1"
    End If
End If
If Not Intersect(Target, Range("P3:P232")) Is Nothing Then
    If Range("S" & Target.Row) = "1" Then
        Application.Wait (Now + TimeValue("0:00:02"))
        Range("V" & Target.Row).Value = "1"
    End If
End If
 
End Sub
 
Upvote 0
Thanks for your further response. I will not be able to run this till later. However, can you clarify the comments in your post. Columns M and P both contain formulas that are involved in creating the circumstances for insertion of data into column S.

Once perfected, this workbook will be used to automatically monitor data received from an online source. There will not be any manual input of date into the workbook.

Will this affect your code?
 
Upvote 0
The code that I provided will not work given the information you just provided. What it boils down to is that in order for a worksheet change event to be recognized it needs to see a manual change. I need to know which cells you are manually changing. In other words in which cells are you inputing data.
 
Upvote 0
I still have a problem then. As mentioned in my earlier post, this workbook will evaluate date from an online source. Once connected to that source, I will not be manually changing any cells.

I am at a loss to understand why when you have such an amazingly powerful tool as Excel that it does not seem able to perform what, to this layman, would appear to be a relatively straightforward task.

It is only the need for a time delay that prevents me from simply using a formula and avoiding VBA altogether.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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