Remove everything before and including #

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
175
Hi Folks,

I think this is quite an easy one - I've seen similar solutions through searching but not quite exactly this.

I have a column with data in it and I want to use vba to get rid of everything before - and including #

So for instance I've got ZP02-TS-GLE#1282255 and I want to get rid of everything except 1282255 for that cell

I want to do this for the whole column.

Any help appreciated


Many Thanks
Tom
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,589
Office Version
365
Platform
Windows
How about
Code:
Sub tomleitch()
   Dim Cl As Range
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      If Cl.Value <> "" Then Cl.Offset(, 1).Value = Split(Cl, "#")(UBound(Split(Cl, "#")))
   Next Cl
End Sub
 

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
175
How about
Code:
Sub tomleitch()
   Dim Cl As Range
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      If Cl.Value <> "" Then Cl.Offset(, 1).Value = Split(Cl, "#")(UBound(Split(Cl, "#")))
   Next Cl
End Sub
Always appreciated Fluff
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
9,648
Office Version
2007
Platform
Windows
How about

Code:
Sub test()
    With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
        .FormulaR1C1 = "=MID(RC[-1],SEARCH(""#"",RC[-1])+1,LEN(RC[-1]))"
        .Value = .Value
    End With
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,589
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,563
Office Version
2010
Platform
Windows
I am assuming your single example is representative of your actual data. If you have header text and that text does not contain a # sign anywhere in it, or if you do not have any header text in Column A at all, then you can use this simple one-liner macro to do what you want...
Code:
Sub Test()
  [A:A].Replace "*#", "", xlPart, , , , False, False
End Sub
If you do have header text and it contains a # sign, then you can use this one-liner macro instead...
Code:
Sub Test()
  Range("A2", Cells(Rows.Count, "A").End(xlUp)).Replace "*#", "", xlPart, , , , False, False
End Sub
 
Last edited:

Forum statistics

Threads
1,085,210
Messages
5,382,369
Members
401,784
Latest member
Jonnyboisme

Some videos you may like

This Week's Hot Topics

Top