ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Replace Function isn't working (https://www.excelbanter.com/excel-programming/347475-replace-function-isnt-working.html)

Adam

Replace Function isn't working
 
I want to replace all blank cells in the group from J4 to the last row with a
-. Here is the macro that I wrote. However, when it runs, it replaces all
blank cells in the sheet, not just the ones that I want. Thank you for your
help.


With wks_E.Range("J4:J" & ExistingFinalRow)
Cells.Replace What:="", Replacement:="-", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With

Tom Ogilvy

Replace Function isn't working
 
Remove the unqualifed "cells", so your replace command is anchored to your
range in column J

With wks_E.Range("J4:J" & ExistingFinalRow)
.Replace What:="", Replacement:="-", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With

an alternative is to put a period in front of cells, but cells is not
necessary, so no use including it.

--
Regards,
Tom Ogilvy

"Adam" wrote in message
...
I want to replace all blank cells in the group from J4 to the last row

with a
-. Here is the macro that I wrote. However, when it runs, it replaces

all
blank cells in the sheet, not just the ones that I want. Thank you for

your
help.


With wks_E.Range("J4:J" & ExistingFinalRow)
Cells.Replace What:="", Replacement:="-", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With





All times are GMT +1. The time now is 07:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com