Unfortunately, this didn't work. The "=sum" is still causing an error. I tried reworking the code, but I couldn't get it to work.
VBA error when trying to delete row when sum equals o
The address in range is =sum ("C2:K2") and is correct, rng equals 0. but I don't know what it can be to make this statement correct. Please help. Trying to delete row when sum equals 0.
Microsoft 365 and Office | Excel | For home | Windows
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
12 answers
Sort by: Most helpful
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
-
Anonymous
2016-01-04T03:01:18+00:00 -
Anonymous
2016-01-04T03:03:40+00:00 As a side note, I might test for SUM( as this has a higher chance of being a function then just "SUM"
(Range name, or an actual Cell ie SUM1 )
Perhaps something like:
If Left$(Rng.Formula, 5) = "=SUM(" And Rng.Value = 0 Then Rng.EntireRow.Delete
Not sure if you would find this useful:
A10 has the formula: =SUM(D10:J10)
Debug.Print [A10].DirectPrecedents.Address(False, False)
Returns:
D10:J10
> ... it is best to sum the row then delete if the entire row is "0".
For R = 10 To 1 Step -1
If WorksheetFunction.Sum(Rows(R)) = 0 Then Rows(R).Delete
Next R
= = = = =
HTH :>)
Dana
I'll try this and let you know. Thanks.
-
Kevin Jones 7,225 Reputation points Volunteer Moderator2016-01-04T04:24:33+00:00 There is a better way--without formulas--but we need to understand the basic task before we can devise an optimal solution.
Please elaborate on this statement: "find 0's both joined by rows and columns to delete".
What rows? What columns? What are you "joining" on?
Try to explain the objective without including any of your current solution that you posted above.
Kevin
-
Anonymous
2016-01-04T04:57:43+00:00 If you can upload your file a precise solution can be provided.