alainfranco

New Member
Joined
Mar 7, 2012
Messages
38
Hello,

Trying to replace a cell that could be emptied by a user by a formula.

Is am using this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("O24").Value = "" Then
Range("O24").Formula = "=IF(G3<>"Completed", "Project not Completed", "Enter Forecasted Budget at Completion")"


End If
End Sub



As you can imagine, its causing an error on the Range("O24").Formula = ....

Any idea how I can get this to work?

Thanks,
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("O24").Value = "" Then
Range("O24").Formula = "=IF(G3<>""Completed"", ""Project not Completed"", ""Enter Forecasted Budget at Completion"")"
End If
End Sub

You can do this, but it will still allow your cell to be changed. If a user changes it to anything other than nothing, it will remain whatever they enter and your formula will be gone.
 
Upvote 0
A sheet change event script will only be activated when a manual change is made to a cell value.
Not when a formula causes a cell value to change.
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("O24").Value = "" Then
Range("O24").Formula = "=IF(G3<>""Completed"", ""Project not Completed"", ""Enter Forecasted Budget at Completion"")"
End If
End Sub

You can do this, but it will still allow your cell to be changed. If a user changes it to anything other than nothing, it will remain whatever they enter and your formula will be gone.


Hi,

Thanks, yup, that did it.... Its the double quotes I was forgetting!

Thanks, much appreciated! :)
 
Upvote 0
You also don't need the End If as you are only testing one condition so it can all go on the one line.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("O24").Value = "" Then Range("O24").Formula = "=IF(G3<>""Completed"", ""Project not Completed"", ""Enter Forecasted Budget at Completion"")"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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