简体   繁体   中英

Move selection down a row and change font color from red to black when there is a change to another sheet

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!!

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

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM