Sub test()
Dim Rng As Range, cl As Range, POS, POS2 As Integer, i As Long
Dim a As Variant
Dim SH As Worksheet
On Error Resume Next
a = Split(InputBox("TYPE SEACHSTRING SPERATE BY A COMA ,"), ",")
For Each SH In ThisWorkbook.Sheets
With SH
For i = 0 To UBound(a)
Set Rng = .Range("B2").CurrentRegion
For Each cl In Rng
POS = InStr(1, cl, a(i), vbTextCompare)
Do Until POS = 0
With cl.Characters(POS, Len(a(i)))
If i = 0 Then
.Font.Bold = True
Else
.Font.Italic = True
End If
End With
POS = InStr(POS + 1, cl, a(i), vbTextCompare)
Loop
Next cl
Next
End With
Next
End Sub
This code work properly if my find text start at cell B2. How about if this text located in various column and row. Hope you can help on this. Thanks so much.hI
Give this code a try
VBA Code:Sub test() Dim Rng As Range, cl As Range, POS, POS2 As Integer, i As Long Dim a As Variant Dim SH As Worksheet On Error Resume Next a = Split(InputBox("TYPE SEACHSTRING SPERATE BY A COMA ,"), ",") For Each SH In ThisWorkbook.Sheets With SH For i = 0 To UBound(a) Set Rng = .Range("B2").CurrentRegion For Each cl In Rng POS = InStr(1, cl, a(i), vbTextCompare) Do Until POS = 0 With cl.Characters(POS, Len(a(i))) If i = 0 Then .Font.Bold = True Else .Font.Italic = True End If End With POS = InStr(POS + 1, cl, a(i), vbTextCompare) Loop Next cl Next End With Next End Sub
Sub test()
Dim Rng As Range, cl As Range, POS As Integer, i As Long
Dim a As Variant
Dim SH As Worksheet
On Error Resume Next
a = Split(InputBox("TYPE SEACHSTRING SPERATE BY A COMA ,"), ",")
For Each SH In ThisWorkbook.Sheets
With SH
Dim FCell As Range
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then Set FCell = .Cells(.Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count)).Row, .Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count), , , 2).Column)
Dim LCell As Range
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then Set LCell = .Cells(.Cells.Find("*", , , , 1, 2) _
.Row, .Cells.Find("*", , , , 2, 2).Column)
Set Rng = Range(FCell.Address, LCell.Address)
For i = 0 To UBound(a)
For Each cl In Rng
POS = InStr(1, cl, a(i), vbTextCompare)
Do Until POS = 0
With cl.Characters(POS, Len(a(i)))
If i = 0 Then
.Font.Bold = True
Else
.Font.Italic = True
End If
End With
POS = InStr(POS + 1, cl, a(i), vbTextCompare)
Loop
Next cl
Next
End With
Next
End Sub
It works in current worksheet only. The others ws not aplied. Im still need ur help if this code can do for all ws. Thanks in advance.TRy
VBA Code:Sub test() Dim Rng As Range, cl As Range, POS As Integer, i As Long Dim a As Variant Dim SH As Worksheet On Error Resume Next a = Split(InputBox("TYPE SEACHSTRING SPERATE BY A COMA ,"), ",") For Each SH In ThisWorkbook.Sheets With SH Dim FCell As Range If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _ Is Nothing Then Set FCell = .Cells(.Cells.Find("*", _ .Cells(.Rows.Count, .Columns.Count)).Row, .Cells.Find("*", _ .Cells(.Rows.Count, .Columns.Count), , , 2).Column) Dim LCell As Range If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _ Is Nothing Then Set LCell = .Cells(.Cells.Find("*", , , , 1, 2) _ .Row, .Cells.Find("*", , , , 2, 2).Column) Set Rng = Range(FCell.Address, LCell.Address) For i = 0 To UBound(a) For Each cl In Rng POS = InStr(1, cl, a(i), vbTextCompare) Do Until POS = 0 With cl.Characters(POS, Len(a(i))) If i = 0 Then .Font.Bold = True Else .Font.Italic = True End If End With POS = InStr(POS + 1, cl, a(i), vbTextCompare) Loop Next cl Next End With Next End Sub
Sub test()
Dim Rng As Range, cl As Range, POS As Integer, i As Long
Dim a As Variant
Dim SH As Worksheet
On Error Resume Next
a = Split(InputBox("TYPE SEACHSTRING SPERATE BY A COMA ,"), ",")
For Each SH In ThisWorkbook.Sheets
With SH
Dim FCell As Range
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then Set FCell = .Cells(.Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count)).Row, .Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count), , , 2).Column)
Dim LCell As Range
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then Set LCell = .Cells(.Cells.Find("*", , , , 1, 2) _
.Row, .Cells.Find("*", , , , 2, 2).Column)
Set Rng = .Range(FCell.Address, LCell.Address)
For i = 0 To UBound(a)
For Each cl In Rng
POS = InStr(1, cl, a(i), vbTextCompare)
Do Until POS = 0
With cl.Characters(POS, Len(a(i)))
If i = 0 Then
.Font.Bold = True
Else
.Font.Italic = True
End If
End With
POS = InStr(POS + 1, cl, a(i), vbTextCompare)
Loop
Next cl
Next
End With
Next
End Sub
Great works. Big thanks for u.Sorry
Me bad
one missing period
VBA Code:Sub test() Dim Rng As Range, cl As Range, POS As Integer, i As Long Dim a As Variant Dim SH As Worksheet On Error Resume Next a = Split(InputBox("TYPE SEACHSTRING SPERATE BY A COMA ,"), ",") For Each SH In ThisWorkbook.Sheets With SH Dim FCell As Range If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _ Is Nothing Then Set FCell = .Cells(.Cells.Find("*", _ .Cells(.Rows.Count, .Columns.Count)).Row, .Cells.Find("*", _ .Cells(.Rows.Count, .Columns.Count), , , 2).Column) Dim LCell As Range If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _ Is Nothing Then Set LCell = .Cells(.Cells.Find("*", , , , 1, 2) _ .Row, .Cells.Find("*", , , , 2, 2).Column) Set Rng = .Range(FCell.Address, LCell.Address) For i = 0 To UBound(a) For Each cl In Rng POS = InStr(1, cl, a(i), vbTextCompare) Do Until POS = 0 With cl.Characters(POS, Len(a(i))) If i = 0 Then .Font.Bold = True Else .Font.Italic = True End If End With POS = InStr(POS + 1, cl, a(i), vbTextCompare) Loop Next cl Next End With Next End Sub