ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Replacing spaces with zeros (https://www.excelbanter.com/excel-programming/361581-replacing-spaces-zeros.html)

Oldjay

Replacing spaces with zeros
 
I have the following

Sub FillZeros()

Sheets("Records").Select
Range("N2:N500").Select
Application.CutCopyMode = False
Cells.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False

End Sub

When I run it I get 5 additional cols of zeros

Oldjay

Ardus Petus

Replacing spaces with zeros
 
Try: Selection.Replace instead of Cells.Replace

HTH
--
AP

"Oldjay" a écrit dans le message de news:
...
I have the following

Sub FillZeros()

Sheets("Records").Select
Range("N2:N500").Select
Application.CutCopyMode = False
Cells.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False

End Sub

When I run it I get 5 additional cols of zeros

Oldjay




Stefi

Replacing spaces with zeros
 
Cells.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False


This statement replaces empty strings "".

Try

Cells.Replace What:=" ", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False


but first check that you want to replace all spaces in all cells
(LookAt:=xlPart) or only those standing alone in a cell (LookAt:=xlWhole)

Regards,
Stefi

€˛Oldjay€¯ ezt Ć*rta:

I have the following

Sub FillZeros()

Sheets("Records").Select
Range("N2:N500").Select
Application.CutCopyMode = False
Cells.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False

End Sub

When I run it I get 5 additional cols of zeros

Oldjay


Tom Ogilvy

Replacing spaces with zeros
 

Sub FillZeros()

Sheets("Records").Select
Range("N2:N500").Select
Application.CutCopyMode = False
Selection.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False

End Sub
--
Regards,
Tom Ogilvy


"Oldjay" wrote:

I have the following

Sub FillZeros()

Sheets("Records").Select
Range("N2:N500").Select
Application.CutCopyMode = False
Cells.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False

End Sub

When I run it I get 5 additional cols of zeros

Oldjay


Oldjay

Replacing spaces with zeros
 
Thanks everybody

"Ardus Petus" wrote:

Try: Selection.Replace instead of Cells.Replace

HTH
--
AP

"Oldjay" a Ʃcrit dans le message de news:
...
I have the following

Sub FillZeros()

Sheets("Records").Select
Range("N2:N500").Select
Application.CutCopyMode = False
Cells.Replace What:="", Replacement:=0, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False

End Sub

When I run it I get 5 additional cols of zeros

Oldjay






All times are GMT +1. The time now is 02:55 AM.

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