By: Bhubon Costa

In reply to 3addoula ma5assak.

Greetings 3ADDOULA MA5ASSAK, thank you for your question. I hope the following codes will solve your issue.

Sub Chemical_Formula()
Dim inputString As String
Dim i As Integer
Dim Char As String
Dim Text As String
Dim Number As String
Dim result As String

inputString = InputBox("Enter the chemical formula:")
result = ""
Text = ""
Number = ""

For i = 1 To Len(inputString)
Char = Mid(inputString, i, 1)
If IsNumeric(Char) Then
Number = Number & Char
Else
If Number <> "" Then
result = result & Text & "=" & Number & ","
Number = ""
End If
If Char Like "[A-Za-z]" Then
Text = Char
End If
End If
Next i

If Number <> "" Then
result = result & Text & "=" & Number
End If

MsgBox result
End Sub

However, if this doesn’t solve your problem, you can mail us your Excel file with detailed instructions to: problem@exceldemy.com, and we’ll try to solve it as soon as possible.