I think that this works:
Option Explicit
Private Sub Worksheet_Calculate()
On Error GoTo errHandler:
If Not IsEmpty(Me.Range("b1")) Then Exit Sub
If Me.Range("a1").Value <> "" Then
Application.EnableEvents = False
Me.Range("b1").Value = Me.Range("a1").Value
End If
errHandler:
Application.EnableEvents = True
End Sub
Notice that we shifted from worksheet_change to worksheet_calculate. Excel
needs to do a calculation to have the fire. But since you have a formula in A1
that depends on A5, it'll fire when A5 changes.
And if you have more than one cell:
Option Explicit
Private Sub Worksheet_Calculate()
Dim myRng As Range
Dim myCell As Range
'these are the "frozen cells"
Set myRng = Me.Range("b1,c8,D10")
On Error GoTo errHandler:
Application.EnableEvents = False
For Each myCell In myRng.Cells
If IsEmpty(myCell) Then
If myCell.Column > 1 Then
If myCell.Offset(0, -1).Value <> "" Then
myCell.Value = myCell.Offset(0, -1).Value
End If
End If
End If
Next myCell
errHandler:
Application.EnableEvents = True
End Sub
That is definitely what I mean. I have absolutely no clue (as you can
probably guess) about VB. I can do a bit of Javascript tinkering but that's
about the extent of my knowledge. Is there anyway, that I can do this:
Cell A1 is the source
Cell B1 is (as already given the locked code)
But in A1 there is a formula IF(A5>0,A5,"") so that B1 will only be
locked if a source figure is greater than zero - i.e. A1 is a formula but
which will only lock the data if there is something >0 to actually lock.
I appreciate your help.
Antony