Home » excel » vba – How do you split part of an excel cell into another cell?

vba – How do you split part of an excel cell into another cell?

Posted by: admin May 14, 2020 Leave a comment

Questions:

There’s a list of cells that looks like [a-z ]* [1-9.]*. I want to split the numric part into the adjacent cell. How can I do this?

How to&Answers:

For another formula approach, you could try this to extract the numeric part of A1:

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),255)

Answer:

here’s a vba snippet, in case this helps:

Dim s As String: s = "wergyuklwgh9235783850298"
Dim i As Long:
For i = 1 To Len(s)
    If Mid(s, i, 1) Like "#" Then Exit For
Next
sLeft = Left(s, i - 1)  ' now sLeft contains "wergyuklwgh"
sRght = Mid(s, i)       ' now sRght contains "9235783850298"

could put this into a public function to make a little UDF, useable from the formula bar