Clear cell Contents if condition is met

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I need a script to clear contents of cells in a range that may contain values less than 1.

The data starts from A7 and I am clearing from the range D7 to N7 down to the last used row.

Thanks
Kelly
 
I am using
A vba code to add and round up values to the sheet and when the source data is blank, then it shows the zeroes in the cells.
If you show us the code that is doing the above, I think we should be able to modify it for you to not output the zeros so that there would be no need to run the extra code to remove them.

By the way, you apparently misled us in you original message... you said you wanted to blank out values less than 1 (which would suggest you had decimal values like 0.45, 0.82, etc.) whereas you actually want to remove cells with 0 in them. I would think this code would do that...
Code:
[table="width: 500"]
[tr]
	[td]Sub ClearLessThanOne()
  Range("D7:N" & Cells(Rows.Count, "A").End(xlUp).Row).Replace 0, "", xlWhole, , , , False, False
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hello this is the code :
Code:
Sub Copy_Add()
    Dim Ms As Worksheet, Cs As Worksheet, x As Long, LastRow, sht As String
    Set Ms = Sheet3
    
    term = Sheet2.Range("E11").Text
    Set Cs = Sheets(sht)
    
    LastRow = Cs.Range("B1007").End(xlUp).Row
    Application.ScreenUpdating = False
    For x = 7 To LastRow Step 1
    With Ms
    .Range("A" & x).Value = Cs.Range("AB" & x).Value
    .Range("B" & x).Value = Cs.Range("B" & x).Value
    .Range("C" & x).Value = Cs.Range("C" & x).Value
    .Range("D" & x).Value = Application.Sum(Cs.Range("G" & x).Value, Application.RoundUp(Cs.Range("P" & x).Value * 0.5, 0))
    .Range("E" & x).Value = Application.Sum(Cs.Range("H" & x).Value, Application.RoundUp(Cs.Range("Q" & x).Value * 0.5, 0))
    .Range("F" & x).Value = Application.Sum(Cs.Range("I" & x).Value, Application.RoundUp(Cs.Range("R" & x).Value * 0.5, 0))
    .Range("G" & x).Value = Application.Sum(Cs.Range("J" & x).Value, Application.RoundUp(Cs.Range("S" & x).Value * 0.5, 0))
    .Range("H" & x).Value = Application.Sum(Cs.Range("K" & x).Value, Application.RoundUp(Cs.Range("T" & x).Value * 0.5, 0))
    .Range("I" & x).Value = Application.Sum(Cs.Range("L" & x).Value, Application.RoundUp(Cs.Range("U" & x).Value * 0.5, 0))
    .Range("J" & x).Value = Application.Sum(Cs.Range("M" & x).Value, Application.RoundUp(Cs.Range("V" & x).Value * 0.5, 0))
    .Range("K" & x).Value = Application.Sum(Cs.Range("N" & x).Value, Application.RoundUp(Cs.Range("W" & x).Value * 0.5, 0))
    .Range("L" & x).Value = Application.Sum(Cs.Range("O" & x).Value, Application.RoundUp(Cs.Range("X" & x).Value * 0.5, 0))
    .Range("M" & x).Value = Cs.Range("Y" & x).Value
    .Range("N" & x).Value = Application.Sum(Ms.Range("D" & x & ":M" & x).Value)
    '.Range("O" & x).Value = Application.CountIf(Ms.Range("D" & x & ":M" & x), "> 0")
    End With
    Next x
End Sub
 
Upvote 0
By the way, you apparently misled us in you original message... you said you wanted to blank out values less than 1 (which would suggest you had decimal values like 0.45, 0.82, etc.) whereas you actually want to remove cells with 0 in them. I would think this code would do that...

Hello I have posted the code for some days now.

Is there a way to fix it as you suggested?

A way to make it better and faster
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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