Results 1 to 2 of 2
  1. #1

    iterations in a excel spreadsheet

    Is there anyway in QTP to iterate through a column in excel sheet to see if a value exists or no.The problem is when you record on a spreadsheet it records only the coordinates where to click etc., and not the column names or anything.So is there a way to do a iteration on particular column.

  2. #2

    Re: iterations in a excel spreadsheet

    Public Function ReadExcelDataSingle(sFileName,iRow,sFieldName,vShe et)
    Dim sData
    Dim iNoError
    Dim sCurrentProc
    Dim sWinDir
    Dim lResult
    Dim strMsgText
    Dim iColNum
    Dim sTestData
    Dim ColHead

    'Count Columns
    ColCount = objWorkSheet.UsedRange.columns.count

    set oSearchRegion = objWorkSheet.Range(objWorkSheet.cells(1,1),objWork Sheet.cells(1, ColCount ))
    notfound = ""
    with oSearchRegion
    set oSearchResult = .Find(sFieldName)
    if not oSearchResult is nothing then
    iColNum = oSearchResult.column
    FirstCol = iColNum
    FoundVal = objWorkSheet.Rows(1).Columns(iColNum).Value
    if sFieldName <> FoundVal then
    set oSearchResult = .Findnext(oSearchResult)
    iColNum = oSearchResult.column
    FoundVal = objWorkSheet.Rows(1).Columns(iColNum).Value
    loop while FirstCol <> iColNum and sFieldName <> FoundVal
    if sFieldName <> FoundVal then notfound = "Y"
    end if
    notfound = "Y"
    end if
    End With

    'Retrieve the value from the cell
    sData = ""
    if notfound = "" then
    sData =objWorkSheet.rows(iRow).Columns(iColNum).Value
    end if

    sData = Trim(sData)

    ReadExcelDataSingle = sData

    End Function
    You can buy my Art from: "Post Cards now available"
    Ian Fraser Landscape Photography
    World Wide Shipping.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 05:34 PM.

Copyright BetaSoft Inc.