Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
I need a vba code to replace all the cells having 0 value with empty cell in
a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
This could be faster; it is simpler...
'-- Sub zerotoblank() Dim rCell As Range For Each rCell In Selection.Cells If rCell.Value = 0 Then rCell.Value = vbNullString Next End Sub -- Jim Cone Portland, Oregon USA "danpt" wrote in message I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
Many thanks, Jim
"Jim Cone" wrote: This could be faster; it is simpler... '-- Sub zerotoblank() Dim rCell As Range For Each rCell In Selection.Cells If rCell.Value = 0 Then rCell.Value = vbNullString Next End Sub -- Jim Cone Portland, Oregon USA "danpt" wrote in message I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
Could you just select the range
Edit|replace what: 0 with: (leave blank) replace all Record a macro when you do it manually and you'll have the code. danpt wrote: I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub -- Dave Peterson |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
You are welcome.
'-- Jim Cone "danpt" wrote in message Many thanks, Jim "Jim Cone" wrote: This could be faster; it is simpler... '-- Sub zerotoblank() Dim rCell As Range For Each rCell In Selection.Cells If rCell.Value = 0 Then rCell.Value = vbNullString Next End Sub -- Jim Cone Portland, Oregon USA "danpt" wrote in message I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub |
#6
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
It wouldn't work with virgin cells in sheets that had never been used.
Sub Macro1() Workbooks("ABC.xls").Sheets("Sheet3").Select Workbooks("ABC.xls").Sheets("Sheet3").Range("C7:F1 2").Select Selection.Replace What:="", Replacement:="0", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub Please explain. Thank you, Dave "Dave Peterson" wrote: Could you just select the range Edit|replace what: 0 with: (leave blank) replace all Record a macro when you do it manually and you'll have the code. danpt wrote: I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub -- Dave Peterson |
#7
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
I thought you wanted to replace the 0's with an empty cell.
That's different from replacing the empty cells with a 0. And if you really wanted to replace the empty cells with a 0 using edit|replace (or the equivalent in a macro), you'll have to make sure that the last used cell is at least as far to the bottom right as you need. If you hit ctrl-end, you'll be taken to this last used cell. If that's not far enough, then just add some temporary text to where you want it to be. Then clear that cell when you're done. danpt wrote: It wouldn't work with virgin cells in sheets that had never been used. Sub Macro1() Workbooks("ABC.xls").Sheets("Sheet3").Select Workbooks("ABC.xls").Sheets("Sheet3").Range("C7:F1 2").Select Selection.Replace What:="", Replacement:="0", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub Please explain. Thank you, Dave "Dave Peterson" wrote: Could you just select the range Edit|replace what: 0 with: (leave blank) replace all Record a macro when you do it manually and you'll have the code. danpt wrote: I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub -- Dave Peterson -- Dave Peterson |
#8
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
You recorded just the opposite of what you originally asked for.
I need a vba code to replace all the cells having 0 value with empty cell Virgin cells do not contain "" so no point looking for them. Gord Dibben MS Excel MVP On Sat, 21 Feb 2009 13:29:01 -0800, danpt wrote: It wouldn't work with virgin cells in sheets that had never been used. Sub Macro1() Workbooks("ABC.xls").Sheets("Sheet3").Select Workbooks("ABC.xls").Sheets("Sheet3").Range("C7:F1 2").Select Selection.Replace What:="", Replacement:="0", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub Please explain. Thank you, Dave "Dave Peterson" wrote: Could you just select the range Edit|replace what: 0 with: (leave blank) replace all Record a macro when you do it manually and you'll have the code. danpt wrote: I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub -- Dave Peterson |
#9
Posted to microsoft.public.excel.misc
|
|||
|
|||
Replacing 0 value with empty
Thank you all,
The reason is that I need to switch between "" and 0 in a chart range, in order to use autochart for better scaliing. I use 0 to indicate non active event. Sorry if I misleaded you. "danpt" wrote: I need a vba code to replace all the cells having 0 value with empty cell in a selected range. Could there be a better way than the following: Sub zerotoblank() Dim r, c, rowstart, rowend, colstart, colend As Long rowstart = Selection.Row rowend = Selection.Rows.Count + rowstart - 1 colstart = Selection.Column colend = Selection.Columns.Count + colstart - 1 For c = colstart To colend For r = rowstart To rowend If Cells(r, c) = 0 Then Cells(r, c) = "" Next r Next c End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Replacing an empty cell | Excel Discussion (Misc queries) | |||
Replacing empty cells with '-' | Excel Worksheet Functions | |||
in excel..:can't empty clip are" but already empty | Excel Discussion (Misc queries) | |||
Excel - Autom. Filter "Empty / Non Empty cells" should come first | Excel Discussion (Misc queries) | |||
How can I convert empty strings to empty cells? | Excel Discussion (Misc queries) |