如果单元格是公式,请select列标题

我已经find了一些代码,但是我不太明白的是如何parsing列,然后select该列中的第一行。

如果所选单元格具有公式,则其目标是为列的标题单元格着色。 我正在寻找的作品是

Sub ColorFormulaHeaders() Dim oWkbk As Workbook Dim oWkst As Worksheet Dim oRng As Range For Each oRng In Selection.Cells If oRng.HasFormula Then 'Select Column Header With Selection .Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent6 .TintAndShade = 0 .PatternTintAndShade = 0 End With End If End Sub 

你有正确的想法。 这是一个到列标题的方法

 Sub ColorFormulaHeaders() Dim oWkbk As Workbook Dim oWkst As Worksheet Dim oRng As Range For Each oRng In Selection.Cells If oRng.HasFormula Then With oRng.EntireColumn.Cells(1).Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent6 .TintAndShade = 0 .PatternTintAndShade = 0 End With End If Next oRng End Sub 

如果标签位于该单元格的列A中,则可以使用类似的技术为某中的单元格获取行标签