Is it possible to get a list of a cell's attributes in excel using VBA? I want to find out if a cell is bold, underlined, in italics, etc. So far all the suggestions i've found on the internet suggests i check if the value is true. For example, in the code below i'm verifying if the cell is bold:
Sub format_cells()
Dim ws As Worksheet
Set ws = Sheets("Uploads")
rc = ws.UsedRange.Rows.Count
For i = 2 To rc
If ws.Cells(i, 10).Font.Bold = True Then
Debug.Print "Pass"
End If
Next
End Sub
I'd rather not have to create a conditional or case statement to check for every possibility. I'd rather just be able to get the properties with one line of code.
For example, in Python I can accomplish this using the Openpyxl library:
from openpyxl import load_workbook
wb = load_workbook("Book1.xlsx")
ws = wb["Uploads"]
ex = ws.cell(2,10)
print(ex.font)
I would then get the following output:
<openpyxl.styles.fonts.Font object>
Parameters:
name='Calibri', charset=None, family=2.0, b=False, i=False, strike=None, outline=None, shadow=None, condense=None, color=<openpyxl.styles.colors.Color object>
Parameters:
rgb=None, indexed=None, auto=None, theme=1, tint=0.0, type='theme', extend=None, sz=11.0, u=None, vertAlign=None, scheme='minor'
But, if i tried doing that in VBA I get a "Run-time error '424' Object required"
Sub test()
Dim ws As Worksheet
Set ws = Sheets("Uploads")
ex = ws.Range("J3")
Debug.Print ex.Font
End Sub
Thank you.