![]() |
best way to test a row for 0 values
what's the best way to test a row, columns c through k to see if all the values
are zeroes? -- Gary |
best way to test a row for 0 values
hit enter too fast. i was thinking of using application.sum. does this make
sense? -- Gary "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... what's the best way to test a row, columns c through k to see if all the values are zeroes? -- Gary |
best way to test a row for 0 values
Sub zerocheck()
Dim testRange As Range, testRow As Long testRow = 2 With ActiveSheet Set testRange = ActiveSheet.Range(.Cells(testRow, "C"), .Cells(testRow, "K")) End With If Application.WorksheetFunction.Sum(testRange) = 0 Then MsgBox "Zero!" Else MsgBox "Non-Zero" End If End Sub -- Cheers Nigel "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... hit enter too fast. i was thinking of using application.sum. does this make sense? -- Gary "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... what's the best way to test a row, columns c through k to see if all the values are zeroes? -- Gary |
best way to test a row for 0 values
Not a good idea as -1 and +1 =0.
Use If Application.Countif(Range("C1:K1"),0) = Range("C1:K1").Cells.Count Then Msgbox "All zero" End If -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... hit enter too fast. i was thinking of using application.sum. does this make sense? -- Gary "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... what's the best way to test a row, columns c through k to see if all the values are zeroes? -- Gary |
best way to test a row for 0 values
That reports zero if none of the cells have zero, because the sum will still
be zero. -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "Nigel" wrote in message ... Sub zerocheck() Dim testRange As Range, testRow As Long testRow = 2 With ActiveSheet Set testRange = ActiveSheet.Range(.Cells(testRow, "C"), ..Cells(testRow, "K")) End With If Application.WorksheetFunction.Sum(testRange) = 0 Then MsgBox "Zero!" Else MsgBox "Non-Zero" End If End Sub -- Cheers Nigel "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... hit enter too fast. i was thinking of using application.sum. does this make sense? -- Gary "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... what's the best way to test a row, columns c through k to see if all the values are zeroes? -- Gary |
best way to test a row for 0 values
ok, thanks bob, there will be an occasional negative number, too.
-- Gary "Bob Phillips" wrote in message ... Not a good idea as -1 and +1 =0. Use If Application.Countif(Range("C1:K1"),0) = Range("C1:K1").Cells.Count Then Msgbox "All zero" End If -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... hit enter too fast. i was thinking of using application.sum. does this make sense? -- Gary "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... what's the best way to test a row, columns c through k to see if all the values are zeroes? -- Gary |
best way to test a row for 0 values
The other thing is that sum will return 0 for blank cells, i.e. they are not
0. |
best way to test a row for 0 values
I was thinking of using application.sum.
Does this make sense? One thing that comes to mind is if one cell has +1, and another has -1, and the rest blank, the Sum is 0. If all are to have 0 value (not blank), then perhaps one of a few ways: Sub Demo() Dim R As Long Dim Rng As Range R = 2 'Your (R)ow Set Rng = Intersect(Rows(R), Range("C:K")) MsgBox WorksheetFunction.CountIf(Rng, "0") = _ Rng.Cells.Count 'or 9 End Sub -- HTH :) Dana DeLouis Windows XP & Office 2003 "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... hit enter too fast. i was thinking of using application.sum. does this make sense? -- Gary "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... what's the best way to test a row, columns c through k to see if all the values are zeroes? -- Gary |
All times are GMT +1. The time now is 11:20 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com