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
==================================================
Bookmarks