Reputation: 1
I have a vba code that works great to keep the selection of one sheet on the same cell when there is a change.
Now, i need a vba code to Move selection down a row and change font color from red to black in another sheet (sheet1 column A) when there is that same change.
Current code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A4")) Is Nothing Then
Application.EnableEvents = False
Me.Range("A5").Value = Target.Value
Target.Select
Application.EnableEvents = True
End If
End Sub
So, when there is a change to Sheet7 cell A4, i need the selection in Sheet1 Column A to drop one row and change the font color from RED to BLACK.Please help!!
Upvotes: 0
Views: 178
Reputation: 1198
Try this one. Again, untested. But I commented out the color change in case the text in Sheet1 Column A is black. You wouldn't be able to see the text if it is.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastRow As Long
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
If Not Intersect(Target, Me.Range("A4")) Is Nothing Then
Application.EnableEvents = False
Me.Range("A5").Value = Target.Value
Target.Select
Sheet1.Range("A" & lastRow + 1).Value = Target.Value
' Sheet1.Range("A" & lastRow + 1).Interior.Color = vbBlack
Application.EnableEvents = True
End If
End Sub
Upvotes: 0
Reputation: 1198
I haven't tested this, but it should be something like this
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A4")) Is Nothing Then
Application.EnableEvents = False
Me.Range("A5").Value = Target.Value
Target.Select
Sheet1.Range("A" & Target.row + 1).Interior.Color = RGB(0, 0, 0)
Application.EnableEvents = True
End If
End Sub
Upvotes: 0