Replace

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Looking to Replace a dash with a Blank in Column D

Below is what I have.

Thank You for any assist.

Code:
Sub ReplaceD()    Dim lastRow As Long
    lastRow = Range("D" & Rows.Count).End(xlUp).Row
    Range("D2:D" & lastRow).Replace what:="-", replacement:="", lookat:=xlWhole
    End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Assuming that that code doesn't work, could you explain why?
 
Upvote 0
That doesn't give us much to go on ;)
Could you post some of your data & what you want?
 
Upvote 0
Is "-" the only thing in each of the cells or is it a part of longer strings? Do you want to replace the "-" with a blank space or with the null string ""?
 
Upvote 0
Yes I'd like to replace the "-" with no space.

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Before[/TD]
[TD]After[/TD]
[/TR]
[TR]
[TD]23200-101[/TD]
[TD]23200101[/TD]
[/TR]
[TR]
[TD]232YM-01[/TD]
[TD]232YM01[/TD]
[/TR]
[TR]
[TD]2333Q-0001[/TD]
[TD]2333Q0001[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
In that case change
Code:
lookat:=xlWhole
to
Code:
lookat:=xlPart
 
Upvote 0
This will do it:
Code:
Sub ReplaceDash()
Application.ScreenUpdating = False
Range("D2:D" & Cells(Rows.Count, "D").End(xlUp).Row).Replace what:="-", replacement:="", lookat:=xlPart
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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