LienDong
Thành viên thường trực
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
- Tham gia
- 22/11/12
- Bài viết
- 218
- Được thích
- 46
- Nghề nghiệp
- Ai nói đúng thì làm!
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 6 And Target.Row > 8 Then
If Target = "Nam" Then
Target.Offset(, 4).Interior.Color = vbRed
ElseIf Target = "N" & ChrW(7919) Then
Target.Offset(, 6).Interior.Color = vbGreen
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Intersect(Target, Range("F9:F500000"))
If Not rng Is Nothing Then
Application.EnableEvents = False
Application.ScreenUpdating = False
Target.Resize(, 7).Interior.Pattern = xlNone
Select Case UCase(Target.Value)
Case "NAM"
Target.Offset(, 4).Interior.Color = 255
Case "N" & ChrW$(7918)
Target.Offset(, 6).Interior.Color = 5287936
Case Else
Target.Offset(, 4).Interior.Color = 65535
Target.Offset(, 6).Interior.Color = 65535
End Select
Application.ScreenUpdating = True
Application.EnableEvents = True
End If
End Sub
Bạn có thể sử dụng Conditional formatting cũng được.Tôi đang tìm hiểu Worksheet_SelectionChange
Tôi muốn Khi nhập "Nam" ở cột f thì cột J tô màu đỏ, còn nhập "Nữ" thì cột L tô màu xanh
Nhờ các bạn viết hộ code trên, cảm ơn các bạn nhiều!
Các bạn cho hỏi, nếu mình xóa số liệu ở cột F (xóa chữ Nam, Nữ) thì báo lỗi "Run - time error 13"Bạn dùng như thế này:
Mã:Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 6 And Target.Row > 8 Then If Target = "Nam" Then Target.Offset(, 4).Interior.Color = vbRed ElseIf Target = "N" & ChrW(7919) Then Target.Offset(, 6).Interior.Color = vbGreen End If End If End Sub
Bạn thêm On error resume next vào codeCác bạn cho hỏi, nếu mình xóa số liệu ở cột F (xóa chữ Nam, Nữ) thì báo lỗi "Run - time error 13"
Cho hỏi cách khắc phục, xin cảm ơn
Đã thêm On error resume next vào codeBạn thêm On error resume next vào code
Thêm như thế nào cho phù hợp thì bạn đọc code trên diễn đàn để tự tùy biến.