PDA

View Full Version : Find and Copy String



jp007_uk
03-25-2015, 01:51 AM
I have a excel sheet where Column Q contains text such as “Reason for change:[new line]AA95072240315125111[new line]Test”
[new line] represents an actual new line I excel and not text.

I need to extract the “AA95072240315125111” into
column R (this will always be 19 characters long) using a VBA Macro.

I assume it would be to find the first : then copy the following 19 characters excluding any spaces and new lines after :

Any help is appreciated, mostly what I’ve found is copying whole cell or row not the actual characters I need.

jonh
03-25-2015, 03:35 AM
In a standard module add


Public Function Getstr(s As String) As String
If InStr(1, s, vbLf) Then Getstr = Split(s, vbLf)(1)
End Function

e.g.
=Getstr(A1)