+ Reply to Thread
Results 1 to 3 of 3

to search the customer name in VBA

  1. #1
    Registered User
    Join Date
    09-18-2009
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    25

    to search the customer name in VBA

    hi I need to find the customer name from the string. the same string is "10000 - mark Peter". so the exisitng code will search the "-" and get the customer. But the case like

    "123100 - William bouch - anc" in that case it returns only "anc" please help me to find this

    ===================================
    Private Sub List_Dimension_Change()
    Dim s_Selection As String
    Dim Position As String
    Dim Ins_Character As String


    s_Selection = List_Dimension.List(List_Dimension.ListIndex)
    If Zip.Value Then s_Selection = Left(s_Selection, InStr(1, s_Selection, " - "))
    If Customer.Value Then
    Position = FindPos(s_Selection, "-")
    Ins_Character = Len(s_Selection) - Len(Replace(s_Selection, "-", ""))
    If Ins_Character = 1 Then
    s_Selection = Right(s_Selection, Position - 1)
    Else
    s_Selection = Right(s_Selection, Len(s_Selection) - Position)
    End If
    End If

    Range("IV2").Value = Support.GenerateSeries(Range("IV2").Value, Trim(s_Selection), List_Dimension.Selected(List_Dimension.ListIndex))
    End Sub
    =====================================


    Function FindPos(InputString As String, SearchString As String) As Long
    Dim l_StrLen As Long, l_RunVar As Long

    l_StrLen = Len(SearchString)
    l_RunVar = InStr(1, InputString, SearchString)

    If l_RunVar > 0 Then
    FindPos = Len(InputString) - l_StrLen

    Do
    FindPos = FindPos - 1
    Loop Until Mid(InputString, FindPos, l_StrLen) = SearchString Or FindPos <= l_RunVar
    Else
    FindPos = l_RunVar

    End If

    End Function
    ==================================================

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: to search the customer name in VBA

    Hi, could you read the forumn rules and use code tags around your post, please
    Last edited by Andrew-R; 10-22-2011 at 04:31 AM.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: to search the customer name in VBA

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1