Run macro on change in value

shaun111

New Member
Joined
May 12, 2008
Messages
30
Hi,

I am struggling with what I know is a very simple piece of code. I was hoping someone could please help?

I would like excel to run a particular Macro (simple copy past value), if the value (formula) in cell "c3" on sheet "assumptions" is anything other than 0.

I am using the following in the code of the "assumptions" sheet which is not working.

rivate Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = False Then Exit Sub
If Not Intersect(Target, Range("C4")) Is Nothing Then
Sheets("Assumptions").Select
Range("C202").Select
Selection.Copy
Range("C201").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

End If


Any suggestions?

Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hello,

Not knowing what your trying to achieve other than the copy and paste, you could try the following.

In VBA select the Assumptions page to write a private Sub (macro)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Range("A1").Value = Range("A2").Value Then


Exit Sub


Else


Range("A2").Value = Range("A1").Value


End If


End Sub
 
Upvote 0
Hi,

I'm not sure exactly if that will help:

I need to the code to automatically rund the macro 'DSRC' every time cell 'B3' in the assumptions sheet is greater or less than 0?
 
Upvote 0
Try this:

Code:
Private Sub Worksheet_Change(byval target as range)

IF Range("B3").Value > 0 or Range("B3").Value < 0 then

'Insert DSRC Macro Here

Else
End If

End Sub
 
Upvote 0
Or
Code:
Private Sub Worksheet_Change(ByVal target As Range)
    If Range("B3").Value <> 0 Then Call DSRC
End Sub
 
Upvote 0
Thanks for the help all, realised that what I was looking for was

Sub Worksheet_Calculate () and not Sub Worksheet_change as I wanted it to calc automatically once the target cell changed, the target cell is the result of a formula.

Ended up using

Private Sub Worksheet_Calculate()

If Sheets("Assumptions").Range("C3").Value > 0 Then
Application.ScreenUpdating = False
DSCR
End If

End Sub

Which seems to work quite well.

Thanks for the help
 
Upvote 0
Pleasure...I'd probably move the screenupdating to the beginning though
Code:
Private Sub Worksheet_Calculate()
Application.ScreenUpdating = False
If Sheets("Assumptions").Range("C3").Value > 0 Then DSCR 
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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