How to find the row number of a specific value in Excel using vbscript

前端 未结 2 1714
情话喂你
情话喂你 2021-02-14 04:32

I have an open Excel file and using VB Script, I need to search only column \"A\" in the Excel sheet until it matches a text string. When the script finds that match, I would l

2条回答
  •  你的背包
    2021-02-14 05:24

    Thanks for the sample. Below it is in VBScript

    Dim FSO, oExcel, oData, FoundCell, WHAT_TO_FIND, File_Path
    
    WHAT_TO_FIND = "Report Summary"
    File_Path = "\\[Server]\[Drive$]\[Folder]\Data.xls"
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oExcel = CreateObject("Excel.Application")
    Set oData = oExcel.Workbooks.Open(File_Path)
    
    Set FoundCell = oData.Worksheets("Sheet1").Range("A4:A20000").Find(WHAT_TO_FIND)
    If Not FoundCell Is Nothing Then
      MsgBox (WHAT_TO_FIND & " found in row: " & FoundCell.Row)
    Else
      MsgBox (WHAT_TO_FIND & " not found")
    End If
    
    Set File_Path = nothing
    Set WHAT_TO_FIND = nothing
    Set FoundCell = nothing
    Set oData = Nothing
    Set oExcel = Nothing
    Set FSO = Nothing
    

提交回复
热议问题