简体   繁体   中英

Excel: get cell collection of cells that contain certain text or formula

I have a worksheet with 1 or more sheets and numerous filled cells per worksheet. I need to go through all cells that have a certain text and/or formula.

What is the quickest way to do this (in .NET)?

An example in VBA, VB.NET or C# would be appreciated.

Paste this macro in your macro editor in your workbook (ALT+F11)

Sub test()
  Dim w As Worksheet, r As Range
  For Each w In ThisWorkbook.Worksheets
    For Each r In w.UsedRange
        If r.Value = "Certain text" Or r.Formula = "Certain Formula" Then
            'Do what you want to do here
        End If
    Next
  Next
End Sub

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM