Micro Focus QTP (UFT) Forums
Splitting value of cell in Excel sheet - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Splitting value of cell in Excel sheet (/Thread-Splitting-value-of-cell-in-Excel-sheet)



Splitting value of cell in Excel sheet - janriis - 02-02-2011

Hi all

I am importing my testdata from an Excel sheet that is provided to me by a colleague and thus pre-formatted.

Column B consists of both First- and Last name, but my app has 2 separate webedit fields for First name and Last name.

What is the VB code for reading the value of a cell until a space and saving it in a variabel like FirstName and then reading the value after the space and saving it in LastName ?


RE: Splitting value of cell in Excel sheet - tarun - 02-02-2011

Try this code

Code:
Dim Row_Count

Row_Count = 0

Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open "c:/Test.xls"

Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

LoopCount = True

Do While LoopCount
    
    LoopCount = True
    Row_Count = Row_Count + 1
    If objSheet.Cells(Row_Count,1) = "" Then
        LoopCount = False
    End If
    
Loop

For i = 1 To Row_Count - 1
    Name = objSheet.Cells(i,2)
    aName = Split(Name," ")
    FirstName = aName(0)
    LastName = aName(1)    
Next



RE: Splitting value of cell in Excel sheet - sreekanth chilam - 02-02-2011

Hi Janris,

Here we go!

Refer the below example.

Code:
Emp_Name="Andy Roberts"
temp=split(Emp_Name," ")
FirstName=temp(0)
LastName=temp(1)

Browser(..).Page(..).WebEdit("FirstName:").Set FirstName
Browser(..).Page(..).WebEdit("LastName:").Set LastName