Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Splitting value of cell in Excel sheet
#1
Solved: 10 Years, 8 Months ago
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 ?
Reply
#2
Solved: 10 Years, 8 Months ago
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
Reply
#3
Solved: 10 Years, 8 Months ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading data from excel sheet serenediva 1 8,582 03-03-2017, 10:07 AM
Last Post: vinod123
  How import final calculated values by cell formula from Excel not the formula itself. qtped 1 4,686 01-17-2017, 04:05 PM
Last Post: sagar.raythatha
Smile Importing Excel sheet - Reference Values are not recognized michiusa69 3 7,567 01-23-2015, 02:36 AM
Last Post: lkng2001
  How to pass a date from Excel sheet to web form revati.shendure 1 2,796 11-27-2014, 11:54 AM
Last Post: revati.shendure
  clearing excel sheet values beejfred 1 7,262 09-25-2014, 11:43 AM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 1 Guest(s)