Advertisement
YasserKhalil2019

T4191_Highlight Half First Word By INDEX Formula Characters

Oct 23rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. https://excel-egy.com/forum/t4191
  2. ---------------------------------
  3.  
  4. Private Sub Worksheet_Change(ByVal Target As Range)
  5. Dim txt As String, startChar As Integer, endChar As Integer, lr As Long
  6.  
  7. If Target.Address = "$K$2" Then
  8. Application.ScreenUpdating = False
  9. lr = Cells(Rows.Count, 1).End(xlUp).Row
  10.  
  11. With Range("L2")
  12. .Formula = "=INDEX($B$2:$B$" & lr & "&""-""&$C$2:$C$" & lr & "&""-""&$D$2:$D$" & lr & ",MATCH(K2,$A$2:$A$" & lr & ",0))"
  13. .Value = .Value
  14. If IsError(.Value) Then .Value = "No Match": GoTo Skipper
  15.  
  16. txt = Split(.Value, "-")(0)
  17. .Characters(1, Len(.Value)).Font.Color = vbBlack
  18. startChar = Application.RoundDown(Len(txt) / 2, 0) + 1
  19. endChar = Len(txt) - startChar + 1
  20. If startChar <> 0 Then .Characters(Start:=startChar, Length:=endChar).Font.Color = RGB(255, 0, 0)
  21. End With
  22. Skipper:
  23. Application.ScreenUpdating = True
  24. End If
  25. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement