Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90288

searching range for first cell with specific font attributes

$
0
0

I am searching a range for the first cell with specific font attributes. I have looked at other solutions to similar problems and followed their example (e.g. Searching for Bold formatted Cells), but the find does not find the cell with the given font attributes -- in the Immediate window I have confirmed that there is a cell in the range that has the TintAndShade & ThemeColor values being searched for.

Help would be much appreciated.

Public Const nThemeColor = xlThemeColorAccent6
Public Const sTintAndShade = -0.249977111117893
Public Function FindFontAttributesRow(rng As Range)
'finds row number of first cell with specific font attributes in a columnar range
Dim FirstAddress As String, Cell As Range
    Application.FindFormat.Clear
    With Application.FindFormat.Font
        .themeColor = nThemeColor
        .TintAndShade = sTintAndShade
    End With
    Set Cell = rng.Find(What:="*", SearchFormat:=True)
    If Not Cell Is Nothing Then
      FindFontAttributesRow = Cell.Row
    Else
        MsgBox "ERROR: dbg"
        Stop
    End If
End Function

I've narrowed down the issue (I think). In the following code, an error 91 ("Object variable or with block variable not set") occurs when SearchFormat=True, but not when it =False, which seems to indicate that the FindFormat object is not being referenced correctly (but I can't figure out how to fix it!).

Sub Macro12()
Dim cel As Range
    Columns("A:A").Select
    Range("A21").Activate
    Application.FindFormat.Clear
    With Application.FindFormat.Font
        .themeColor = 10
    End With

    Range("A21").Activate
    ThisWorkbook.ActiveSheet.Columns("A:A").Find(What:="*", SearchFormat:=True).Activate
End Sub

Viewing all articles
Browse latest Browse all 90288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>