Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 7 of 7

Thread: Extract Left Most Characters Until a Space

  1. #1
    Join Date
    6th October 2006
    Posts
    8

    Extract Left Most Characters Until a Space

    I am trying to write a function that finds and breaks a cell about the first space.
    Worksheet is:
    =LEFT(name,FIND(" ",name)-1)

    Have tried...

    VB:
    Function Firstname(name) 
         
        Dim Space As Integer 
         
        Set Space = .Find(" ", name) 
         
        Firstname = Left(name, Space) 
         
    End Function 
    
    
    and also...

    VB:
    Function Firstname(name) 
         
        firstname = left(name,find(" ",name)-1)) 
         
    End Function 
    
    

    What am i doing wrong?

    Cheers

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,716

  3. #3
    Join Date
    6th October 2006
    Posts
    8

    Re: What Is The Vba Equivalent Of Worksheet =find(" ",a2)

    how is my question not accurate? I want to know the VBA equivalent of
    =find(" ",A2)

    I don't think that I could ask any clearer than that.

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,716

    Re: What Is The Vba Equivalent Of Worksheet =find(" ",a2)

    See the new thread title which is along the lines of what you agreed to. Hvae you read the rules?

  5. #5
    Join Date
    6th October 2006
    Posts
    8

    Re: Extract Left Most Characters Until a Space

    Ok, sweet. Get ya


    BUT


    what am I looking for thats going to make that work in VBA? I want my staff/users to simply right a formula sort of along the lines:

    =firstname(name)
    =lastname(name)

    I get all the left, right etc, but am not sure how to find the first space.

    Cheers.

    Excel Video Tutorials / Excel Dashboards Reports


  6. #6
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,716

    Re: Extract Left Most Characters Until a Space

    Try
    VB:
    Function FirstName(Cell_Name As Range) As String 
        Dim lSpace As Long 
        Dim strName As String 
         
        strName = Trim(Cell_Name) 
         
        lSpace = InStr(1, strName, " ", vbTextCompare) 
         
        FirstName = Trim(Left(strName, lSpace)) 
         
    End Function 
    
    

  7. #7
    Join Date
    6th October 2006
    Posts
    8

    Re: Extract Left Most Characters Until a Space

    Most excellent!!

    Thanks a whole bunch!



    Made the right argument now.

    VB:
    Function LastName(Cell_Name As Range) As String 
        Dim lSpace As Long 
        Dim strName As String 
         
        strName = Trim(Cell_Name) 
         
        lSpace = InStr(1, strName, " ", vbTextCompare) 
         
        LastName = Trim(Right(strName, Len(strName) - lSpace)) 
         
    End Function 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Trim Left Of Space
    By CustomGT in forum EXCEL HELP
    Replies: 5
    Last Post: May 16th, 2007, 01:46
  2. Remove All Text Left Of Space And The Space
    By liiv17 in forum EXCEL HELP
    Replies: 12
    Last Post: February 10th, 2007, 06:38
  3. Extract Left Characters Up Until Specified Text
    By regionrat2004 in forum EXCEL HELP
    Replies: 19
    Last Post: November 10th, 2006, 06:01
  4. Copying Data To Left of Space Using Left Function
    By chathabox in forum EXCEL HELP
    Replies: 6
    Last Post: June 27th, 2006, 18:21
  5. Remove characters after a space
    By YoBro in forum EXCEL HELP
    Replies: 3
    Last Post: January 22nd, 2005, 14:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno