I don't know if I am even using the correct event, but what I am trying to achieve is that when a user enters a value in one particular cell, other cells are filled in, based on that value.
The following code, which is attached to the relevent sheet, sort of works, in that the writes to the cells only happen if the user clicks on the cell again after they have changed the value (e.g. change value in O2, press enter or click on another cell and nothing happens. Click on O2 again and the cells are filled-in correctly)
Is there a way of firing the macro immediately the user presses enter after entering data or clicks on another cell?
I should point out that there is an excel cell formula that uses the value of the cell (e.g. value in N2 "= M2-02") - I don't know if that would affect the running of this macro
Thanks
The following code, which is attached to the relevent sheet, sort of works, in that the writes to the cells only happen if the user clicks on the cell again after they have changed the value (e.g. change value in O2, press enter or click on another cell and nothing happens. Click on O2 again and the cells are filled-in correctly)
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
Dim Remainder As Float
' never more than 10K rows so following should be ok
If Not Application.Intersect(Target, Me.Range("O2:O65000")) Is Nothing Then
i = ActiveCell.Row
Remainder = Range("O" & i).Value
'MsgBox (CStr(Remainder))
' Just in case previous value set back to zero
If Remainder = 0 Then
Range("V" & i).Value = 0
Range("W" & i).Value = 0
Range("X" & i).Value = 0
Range("Y" & i).Value = 0
Range("Z" & i).Value = 0
Range("AA" & i).Value = 0
Range("AB" & i).Value = 0
Exit Sub
End If
'Value ok - Assign it
If Remainder >= Range("N" & i).Value Then
Range("V" & i).Value = Range("M" & i).Value
Range("W" & i).Value = Range("I" & i).Value
Range("X" & i).Value = Range("K" & i).Value
Range("Y" & i).Value = Range("J" & i).Value
Range("Z" & i).Value = Range("H" & i).Value
Range("AA" & i).Value = Remainder - Range("N" & i).Value
Range("AB" & i).Value = 0
Exit Sub
ELSE
'More code to go here to divvy out the value based on values in other cells
End If
End If
End Sub
Is there a way of firing the macro immediately the user presses enter after entering data or clicks on another cell?
I should point out that there is an excel cell formula that uses the value of the cell (e.g. value in N2 "= M2-02") - I don't know if that would affect the running of this macro
Thanks