VB Question

  • Thread starter Thread starter flashpest
  • Start date Start date
F

flashpest

I have a conditional format I need to occur and it must be done in VB
It is a list of ten words and when a certain cell has one of thes
words typed into it, it needs to be underlined. Can someone help??


Thank you,
Eri
 
One way:

Put this in your worksheet code module:


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim vArr As Variant
Dim i As Long
Dim sValue As String

With Target(1)
If .Address(False, False) = "A1" Then
.Font.Underline = False
vArr = Array("one", "two", "three", "four", "five", _
"six", "seven", "eight", "nine", "ten")
sValue = LCase(.Value)
For i = LBound(vArr) To UBound(vArr)
If sValue = vArr(i) Then
.Font.Underline = True
Exit For
End If
Next i
End If
End With
End Sub
 
Hi Erik,

Another version

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim i As Long
Dim sValue As String

On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Range("A1:H10")) Is Nothing Then
With Target
Select Case LCase(.Value)
Case "one", "two", "three", "four", "five", _
"six", "seven", "eight", "nine", "ten":
.Font.Underline = True
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


Change the range to check from A1:H10 to suit, and the words to suit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top