Search code examples
excelvbacombobox

Parse a substring from ComboBox selection


I have a ComboBox "Liste_cible" with values like: BOCAL SAP-A246, or PAP-SAP-K207.

I would like to use only the last number, after the "-" (A246 or K207) to run another subroutine.

I'm looking for the function like SUBTSTR(Me.Liste_cible.Value,”-“,-1)

Private Sub liste_cible_Change()
Dim argString As String
If Not Worksheets("1 - Feuille de Suivi Commercial").Liste_cible.MatchFound And Worksheets("1 - 
 Feuille de Suivi Commercial").Liste_cible <> "" Then
  MsgBox "Saisie impossible, ce partenaire cible n'existe pas !", , "Contrôle"
  Worksheets("1 - Feuille de Suivi Commercial").Liste_cible = ""
 Else
  Worksheets("1 - Feuille de Suivi Commercial").Cells(5, 17) = Worksheets("1 - Feuille de Suivi    
  Commercial").Liste_cible
  MsgBox Me.Liste_cible.Value
  argString = SUBTSTR(Me.Liste_cible.Value,”-“,-1)  ??
  GET_GROUPE_GESTION_CIBLE (argString)
  INFO_PROTO1 (argString)
  INFO_PROTO2 (argString)
  End If
  End Sub

MsgBox Me.Liste_cible.Value works correctly, but I don't know how to get the argString.


Solution

  • This should do the trick:

    argString = Mid(Me.Liste_cible.Value, InStrRev(Me.Liste_cible.Value,"-") + 1)