简体   繁体   中英

Excel VBA Change Next Cell Text Color ERROR

Excel VBA 2010

This is a quick function that when the user click on a cell (A Column), it creates a checkmark. I also want the function to make the text in adjacent cell (B column) change color.

I'm currently getting this error:
Run-time error '9': Subscript out of Range

It highlights this line:
Target.Offset(0,1).Interior.ColorIndex = RGB(77, 191, 46)

Here's the full code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("A3:A20")) Is Nothing Then
        Target.Font.Name = "Marlett"
            If Target = vbNullString Then
                Target = "a"
                Target.Offset(0, 1).Interior.ColorIndex = RGB(77, 191, 46)
            Else
                Target = vbNullString
                Target.Offset(0, 1).Interior.ColorIndex = RGB(0, 0, 0)
            End If

    End If
End Sub

Any Advice??

更改.Interior.ColorIndex.Font.Color和应该做的:)

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