How to remove text from a cell in vba

Macro_Nerd99

Board Regular
Joined
Nov 13, 2021
Messages
61
Office Version
  1. 365
If I had a cell that has an address stated like this:

Number: 1921 Street name: Main st.

How do I remove the text "Number:" and the text "Street name:" and the space in between, so It just has the address: "1921 Main st."
I've been trying to use the split function in other cells, but this one has 2 colons so it's hard.


Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You could obviously run this against a range of values, not just cell A1.
VBA Code:
Sub macro_nerd()
With Range("A1")
    .Value = Replace(Replace(.Value, "Number: ", ""), "Street name: ", "")
End With
End Sub
 
Upvote 0
You could just do a replace

VBA Code:
With Sheets("Sheet1")
    .Columns(1).Replace "Number: ", ""
    .Columns(1).Replace "Street name: ", ""
End With
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

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