Option Explicit
Sub gpeToMau()
Dim StrC As String, VTr As Byte, jJ As Byte
Const KT = " "
StrC = Selection.Value
Do
VTr = InStr(VTr + 1, StrC, KT)
If VTr < 1 Then Exit Do
TMau VTr - 1
Loop
End Sub
[SIZE=2][B]Sub TMau(TM As Byte)[/B]
With ActiveCell.Characters(Start:=TM, Length:=1).Font
.ColorIndex = 3
End With
[B]End Sub[/B][/SIZE]
PHP:Option Explicit Sub gpeToMau() Dim StrC As String, VTr As Byte, jJ As Byte Const KT = " " StrC = Selection.Value Do VTr = InStr(VTr + 1, StrC, KT) If VTr < 1 Then Exit Do TMau VTr - 1 Loop End Sub
Mã:[SIZE=2][B]Sub TMau(TM As Byte)[/B] With ActiveCell.Characters(Start:=TM, Length:=1).Font .ColorIndex = 3 End With [B]End Sub[/B][/SIZE]
Thêm nữa Thầy có thể chuyển cho em code trên thành Hàm tự tạo được khộng ạ?
Hàm tự tạo tại ô C7. Nghĩa là nhập dữ liệu vào ô C7 enter thì code sẽ tự tô màu mà không cần phải kích hoạt code cho mỗi lần nhập nữa ạ!
Em xin cảm ơn!
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim StrC As String, VTr As Byte, jJ As Byte, Cuoi As Byte
Const KT = " "
If Not Intersect(Target, Columns("c:C")) Is Nothing Then
StrC = Selection.Value
Do
Cuoi = VTr
VTr = InStr(VTr + 1, StrC, KT)
If VTr >= 1 Then
TMau VTr - 1
Else
Exit Do
End If
Loop
TMau Cuoi, 9
End If
End Sub
[B]Sub TMau(TM As Byte, Optional Mot As Byte = 1)
[/B] With ActiveCell.Characters(Start:=TM, Length:=Mot).Font
.ColorIndex = IIf(Mot = 1, 3, 4)
End With
[B]End Sub
[/B]