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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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.

BeforeAfter
23200-10123200101
232YM-01232YM01
2333Q-00012333Q0001

<tbody>
</tbody>
 
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,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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