This code works perfectly if the text is in a cell on sheet, but gives an error if the same code is applied to a userform textbox:
The only change I made was changing the D14 cell range to Textbox1 as below:
I just want to do the same thing when the text is in a userform textbox, NOT in a sheet cell. Here's the errorImage below)
Why does this work for text in a cell but generates an error if the same code is used in a userform textbox?
All I want to do is color the text between the first comma from the beginning of the text and the first period it encounters, as s and f indicate.
This seems very doable and not overly complex to do. Any help would be appreciated
Thanks, cr.
Code:
Private Sub CommandButton1_Click()
Dim s As Variant
Dim f As Variant
With Range("D14")
s = WorksheetFunction.Find(",", .Value, 1)
f = WorksheetFunction.Find(".", .Value, 1)
.Characters(s, f - s + 1).Font.Color = vbRed
End With
End Sub
The only change I made was changing the D14 cell range to Textbox1 as below:
Code:
Private Sub cmdCOLORTEXT_Click()
Dim s As Variant
Dim f As Variant
With TextBox1 'TextBox1 'Range("D14") - changed from Range("D14") to Textbox1
s = WorksheetFunction.Find(",", .Value, 1)
f = WorksheetFunction.Find(".", .Value, 1)
.Characters(s, f - s + 1).Font.Color = vbRed
End With
I just want to do the same thing when the text is in a userform textbox, NOT in a sheet cell. Here's the errorImage below)
Why does this work for text in a cell but generates an error if the same code is used in a userform textbox?
All I want to do is color the text between the first comma from the beginning of the text and the first period it encounters, as s and f indicate.
This seems very doable and not overly complex to do. Any help would be appreciated
Thanks, cr.