DogsbodyBoy
New Member
- Joined
- Oct 24, 2022
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
I have the following VBA code on a worksheet. It works as designed by converting alpha characters to upper case and performing a lookup in another worksheet in cell range A1:B26. I should point out that I also have data validation in place so that only one letter can be typed into a cell. In other words, if the user types in the letter b in lower case, the VBA code automatically converts it to upper case and looks up the letter B in range A1:B26 of the other worksheet. If the user types in bb then data validation prevents the entry from occurring.
I'm trying to modify the code so that if the entered value is in regular font, then it proceeds as specified above. However, if the value is in italic font, then I want to change the lookup range in the other worksheet to D1:E26. Does anyone know if or how this can be done?
Many thanks
I'm trying to modify the code so that if the entered value is in regular font, then it proceeds as specified above. However, if the value is in italic font, then I want to change the lookup range in the other worksheet to D1:E26. Does anyone know if or how this can be done?
Many thanks
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Convert all alpha charaters to upper case and lookup the entered value in the Tile Values worksheet range A1:B26
Dim Z As Long
Dim xVal As String
On Error Resume Next
If Intersect(Target, Range("B4:P18")) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Z = 1 To Target.Count
If Target(Z).Value > 0 Then
Target(Z).Value = StrConv(Target(Z).Value, 1)
End If
Next
Application.EnableEvents = True
If Not Intersect(Target, Range("B4:P18")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
Dim f As Range
Set f = Worksheets("Tile Values").Range("A1:B26").Find(Target.Value, , xlValues, xlWhole, , , False)
If Not f Is Nothing Then
Application.EnableEvents = False
If Range("X20").Text = False Then
Target.Value = f.Offset(, 1).Value
End If
With Target.Characters(Start:=2, Length:=2).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 14
.Strikethrough = False
.Superscript = True
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
Application.EnableEvents = True
End If
End If
End Sub