Remove everything before and including #

tomleitch

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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

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
Back
Top