There are two columns A & B:
If the input value in B is "Y", then the formula in A should get replaced with its static value obtained from formula. If B is empty A keeps its formula.
How can I achieve this for all rows?
If I understood your question correctly, this can be done with the Worksheet_Change
Event . This event occurs when a cell ( Target
) is changed.
So you just need to check if the Target.Column
is the second column and if its value is Y
and then move one column left Target.Offset(0, -1)
and replace the value.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target.Value = "Y" Then
Target.Offset(0, -1).Value = Target.Offset(0, -1).Value
End If
End Sub
Note that the input value Y
is case sensitive and only works for upper case Y
. To make it non case sensitive use UCase(Target.Value) = "Y"
instead to accept lower case y
as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.