RE: change selected value x of FIND method to appear red and bold in userform results view. ..

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
877
Office Version
  1. 365
Platform
  1. Windows
Title explains it. This code finds all values of X , at beginning, in the middel or at the end of cell text down a column and displays results in RESULT sheet.
Everybody is familiar with this standard FIND method code:
Code:
Private Sub CommandButton1_Click()
Dim X As String
Dim c As Range
Dim rw As Long
Dim firstaddress As Variant
Dim rowno As Integer
[B]X = Me.TextBox1.Value --->value to FIND and (1) color Font red and (2) change to Bold[/B]
With Worksheets("KJV").Range("A2:B31103")
Set c = .Find(X, LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
rw = 2
firstaddress = c.Address
Do
Worksheets("KJV").Select
c.Select
[B]'Selection.Font.Color = RGB(255, 0, 0)<---maybe code should go here. This just colors the entire text found in the cell red – NOT just the value of X (which is what I want)[/B]
MsgBox "Value found in cell " & c.Address
Destination:=Sheets("RESULT").Range("A" & rw)
Range(Cells(c.Row, 1), Cells(c.Row, 2)).Copy Destination:=Sheets("RESULT").Range("A" & rw)
rw = rw + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
rowno = Sheets("RESULT").Range("B2").End(xlDown).Row
MsgBox rowno
Sheets("RESULT").Range("B1").Value = rowno
Me.TextBox2.Value = Sheets("RESULT").Range("B1").Value

And it works very well - faster than Autofilter. (searching in column with 31,000 rows of data)
If the value of x = "embrace", the code above gives 14 results and displays the entire cell text
as below image. Note that the DESIRED RESULT image has the value of X in red and bolded. But that
is in the sheet's cell value - NOT in the userform. The yellow highlighted value in the form is what
I want to "appear" ref and bolded.

How would I tell excel: "OK, now that the value of x is found in all rows, just display x in
red and bolded in the userform - not the cell text. (The userform does not display it in red and bolded
even if the underlying value in the sheet cell is colored red and bolded. )

Thanks for anyone's help. Apologies for long explanation. Wanted to show all that I needed to have done.
cr
 

Attachments

  • SEARCH VALUE.jpg
    SEARCH VALUE.jpg
    30.7 KB · Views: 11
  • EMBRACE RESULT.jpg
    EMBRACE RESULT.jpg
    74.7 KB · Views: 11
  • DESIRED RESULT.jpg
    DESIRED RESULT.jpg
    24.1 KB · Views: 11

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You can't do that with standard form controls. You'd need something like a richtext edit box, or perhaps an Ink control (I haven't verified they will do that either though)
 
Upvote 0

Forum statistics

Threads
1,213,537
Messages
6,114,216
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top