Si è più complessa di quanto sembri. Un kx + m può avere Max 7 operatori e minimo 1 Operatore se non sbaglio. E in uno scenario del genere diventa davvero complesso ottenere i valori "K" e "M". - Siddharth Rout 33 min fa
Basandosi sul mio commento nel post di duffymo
Questa istantanea mostra le diverse combinazioni che “kx + m” possono avere

E come suggerito in precedenza, è molto complesso ottenere quello che vuoi. Ecco il mio tentativo debole per estrarre solo "K" al momento. Questo codice non è in alcun modo di classe :(Anche io non ho testato il codice con diversi scenari in modo che possa fallire con gli altri.Tuttavia ti dà una buona idea su come affrontare questo problema. aggiustalo di più per ottenere i risultati esatti che vuoi.
CODICE (Sto testando per 7 combinazioni possibili in questo codice.Funziona per questi 7 ma potrebbe/fallirà per gli altri)
Option Explicit
Sub Sample()
Dim StrCheck As String
Dim posStar As Long, posBrk As Long, pos As Long, i As Long
Dim strK As String, strM As String
Dim MyArray(6) As String
MyArray(0) = "-k*(-x)+(-m)*(-2)"
MyArray(1) = "-k*x+(-m)*(-2)"
MyArray(2) = "-k(x)+(-m)*(-2)"
MyArray(3) = "-k(x)+(-m)(-2)"
MyArray(4) = "-kx+m"
MyArray(5) = "kx+m"
MyArray(6) = "k(x)+m"
For i = 0 To 6
StrCheck = MyArray(i)
Select Case Left(Trim(StrCheck), 1)
Case "+", "-"
posBrk = InStr(2, StrCheck, "(")
posStar = InStr(2, StrCheck, "*")
If posBrk > posStar Then '<~~ "-k*(-x)+(-m)*(-2)"
pos = InStr(2, StrCheck, "*")
If pos <> 0 Then
strK = Mid(StrCheck, 1, pos - 1)
Else
strK = Mid(StrCheck, 1, posBrk - 1)
End If
ElseIf posBrk < posStar Then '<~~ "-k(-x)+(-m)*(-2)"
pos = InStr(2, StrCheck, "(")
strK = Mid(StrCheck, 1, pos - 1)
Else '<~~ "-kx+m"
'~~> In such a case I am assuming that you will never use
'~~> a >=2 letter variable
strK = Mid(StrCheck, 1, 2)
End If
Case Else
posBrk = InStr(1, StrCheck, "(")
posStar = InStr(1, StrCheck, "*")
If posBrk > posStar Then '<~~ "k*(-x)+(-m)*(-2)"
pos = InStr(1, StrCheck, "*")
If pos <> 0 Then
strK = Mid(StrCheck, 1, pos - 2)
Else
strK = Mid(StrCheck, 1, posBrk - 1)
End If
ElseIf posBrk < posStar Then '<~~ "k(-x)+(-m)*(-2)"
pos = InStr(1, StrCheck, "(")
strK = Mid(StrCheck, 1, pos - 2)
Else '<~~ "kx+m"
'~~> In such a case I am assuming that you will never use
'~~> a >=2 letter variable
strK = Mid(StrCheck, 1, 1)
End If
End Select
Debug.Print "Found " & strK & " in " & MyArray(i)
Next i
End Sub
ISTANTANEA

Non è molto, ma spero che questo si ottiene in strada giusta ...
+! per una domanda interessante :) –