VBA to identify italic font

DogsbodyBoy

New Member
Joined
Oct 24, 2022
Messages
20
Office Version
  1. 365
Platform
  1. 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

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
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I didn't understand exactly what you are trying to achieve but you can adopt the example below:
VBA Code:
If Worksheets("Sheet1").Range("A1:A5").Font.Italic Then
  'Do some stuff
Else
  'Do other stuff
End If
 
Upvote 0
Thanks, Flashbond. I think this is what I need.

Is there a difference between between Italic and Bold Italic?
How do I make the range equal to the active cell?
 
Upvote 0
This code If ActiveCell.Font.Italic Then will recognize italic even it is bold.

I think this should work. To check both at the same time:
VBA Code:
If ActiveCell.Font.Italic And ActiveCell.Font.Bold Then
  'Do stuff
Else
  'Do other stuff
End If
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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