Remove everything before and including #

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
188
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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,523
Office Version
  1. 365
Platform
  1. 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
188
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
12,619
Office Version
  1. 2007
Platform
  1. 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
56,523
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

You're welcome & thanks for the feedback
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,971
Office Version
  1. 2016
Platform
  1. 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:

Watch MrExcel Video

Forum statistics

Threads
1,129,467
Messages
5,636,462
Members
416,919
Latest member
twc2c

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top