用途:整理excel格式和展示方式
Sub KeyWordHighlight()
Dim str() As String
Dim strLen As Integer
With Columns("P")
.ColumnWidth = .ColumnWidth * 8
.WrapText = True
End With
For x = 2 To Range("P2").End(xlDown).Row
str = Split(Cells(x, 15).Value, ";")
If Cells(x, 14) = 3 Then
strLen = UBound(str)
Else:
strLen = UBound(str) - 1
End If
For num = 0 To strLen
For y = 1 To Len(Cells(x, 16).Value) - Len(str(num))
If str(num) = Mid(Cells(x, 16).Value, y, Len(str(num))) Then
Cells(x, 16).Characters(y, Len(str(num))).Font.Color = vbRed
End If
Next
Next
Next
MsgBox "Done"
End Sub
'将P列的列宽扩大到原来的8倍,同时设置自动换行
With Columns("P")
.ColumnWidth = .ColumnWidth * 8
.WrapText = True
End With
'从第二行开始到最后一行,O行单元格内容通过<;>进行分割,并将其在P列标红展示
For x = 2 To Range("P2").End(xlDown).Row
str = Split(Cells(x, 15).Value, ";")
If Cells(x, 14) = 3 Then
strLen = UBound(str)
Else:
strLen = UBound(str) - 1
End If
For num = 0 To strLen
For y = 1 To Len(Cells(x, 16).Value) - Len(str(num))
If str(num) = Mid(Cells(x, 16).Value, y, Len(str(num))) Then
Cells(x, 16).Characters(y, Len(str(num))).Font.Color = vbRed
End If
Next
Next
Next
标签:VBA,num,第一个,Cells,Len,人生,str,End,strLen
From: https://www.cnblogs.com/hiko-daydayup/p/18336349