U
uglyvb
Hi all,
I get stuck again in macro in Excel...What I need is fairly simple:
Immediately after a cell, say C6, lost focus, a corresponding cell, say
C12 is getting updated with the same/new value as C6. I tried to use
SelectionChange as follows:
Public Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim RNQVal As Integer
Dim RowVal As Integer
Dim ColVal As Integer
' Now get the row, column number and the value of the RNQ cell
(analogous to C6 in the description)
RowVal = Target.Row
ColVal = Target.Column
If (ColVal = 7 And RowVal > 25) Then
' validate the value just entered into the cell
RNQVal = Target.Value
' Set the corresponding DNQ cell(analogous to C12 in the
description) with the same value
Cells(RowVal, ColVal + 6).Locked = False
Cells(RowVal, ColVal + 6).Value = RNQVal
Cells(RowVal, ColVal + 6).Locked = True
End If
End Sub
But the above code snippet does not do exactly as expected. It does NOT
update C12 immediately after moving the cursor from C6, but does so when
C6 regains the focus afterwards. I searched the Internet almost for the
whole day trying to get through, but I just cannot!! There's no helpful
information at all on LostFocus, though it seems like what I need. I
could not even find any code sample on LostFocus either
....Any help would be highly appreciated. Thanks in advance!!
I get stuck again in macro in Excel...What I need is fairly simple:
Immediately after a cell, say C6, lost focus, a corresponding cell, say
C12 is getting updated with the same/new value as C6. I tried to use
SelectionChange as follows:
Public Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim RNQVal As Integer
Dim RowVal As Integer
Dim ColVal As Integer
' Now get the row, column number and the value of the RNQ cell
(analogous to C6 in the description)
RowVal = Target.Row
ColVal = Target.Column
If (ColVal = 7 And RowVal > 25) Then
' validate the value just entered into the cell
RNQVal = Target.Value
' Set the corresponding DNQ cell(analogous to C12 in the
description) with the same value
Cells(RowVal, ColVal + 6).Locked = False
Cells(RowVal, ColVal + 6).Value = RNQVal
Cells(RowVal, ColVal + 6).Locked = True
End If
End Sub
But the above code snippet does not do exactly as expected. It does NOT
update C12 immediately after moving the cursor from C6, but does so when
C6 regains the focus afterwards. I searched the Internet almost for the
whole day trying to get through, but I just cannot!! There's no helpful
information at all on LostFocus, though it seems like what I need. I
could not even find any code sample on LostFocus either
....Any help would be highly appreciated. Thanks in advance!!