Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
function for checking for an odd number
This code works but the division should always give an even number. I'm
trying to error check for an accidental odd number of rows in the irwo(service group column). The code should continue but give an error message. There are 2 lines in the code that have division and they should both be even quotients. Should I put the resume Next on both lines for it to error check for both lines? The other question is if both numbers are integers when they divide what would be the function to get it to throw an error if it is not an even division? tia, -----section of code--------- For iRow = LastRow To FirstDataRow Step -1 i = i + 1 If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1, ServiceGroupColumn).Value Then Else On Error Resume Next rowsToAdd = (40 - i) / 2 .Cells(iRow, ServiceGroupColumn).Offset(i / 2).Resize(rowsToAdd).EntireRow.Insert If Err.Number < 0 Then MsgBox Err.Description, vbCritical End If i = 1 End If Next iRow End With End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
function for checking for an odd number
Function testit(n As Long, m As Long) As String
If n Mod m = 0 Then testit = "even divisor" Else testit = "not even divisior" End If End Function -- Gary''s Student - gsnu200748 "Janis" wrote: This code works but the division should always give an even number. I'm trying to error check for an accidental odd number of rows in the irwo(service group column). The code should continue but give an error message. There are 2 lines in the code that have division and they should both be even quotients. Should I put the resume Next on both lines for it to error check for both lines? The other question is if both numbers are integers when they divide what would be the function to get it to throw an error if it is not an even division? tia, -----section of code--------- For iRow = LastRow To FirstDataRow Step -1 i = i + 1 If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1, ServiceGroupColumn).Value Then Else On Error Resume Next rowsToAdd = (40 - i) / 2 .Cells(iRow, ServiceGroupColumn).Offset(i / 2).Resize(rowsToAdd).EntireRow.Insert If Err.Number < 0 Then MsgBox Err.Description, vbCritical End If i = 1 End If Next iRow End With End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
function for checking for an odd number
Here is a function that will return True if the value passed into it is odd
and False if it is even. Function IsOdd(Value As Long) As Boolean IsOdd = Value And 1 End Function So, to use it, you would call it like this... If IsOdd(SomeValue) Then ' The value in SomeValue is an odd number Else ' The value in SomeValue is an even number End If Obviously, the test is simple enough to use directly within your code, without encasing it in a Function, if you want... If SomeValue And 1 Then ' The value in SomeValue is an odd number Else ' The value in SomeValue is an even number End If Rick "Janis" wrote in message ... This code works but the division should always give an even number. I'm trying to error check for an accidental odd number of rows in the irwo(service group column). The code should continue but give an error message. There are 2 lines in the code that have division and they should both be even quotients. Should I put the resume Next on both lines for it to error check for both lines? The other question is if both numbers are integers when they divide what would be the function to get it to throw an error if it is not an even division? tia, -----section of code--------- For iRow = LastRow To FirstDataRow Step -1 i = i + 1 If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1, ServiceGroupColumn).Value Then Else On Error Resume Next rowsToAdd = (40 - i) / 2 .Cells(iRow, ServiceGroupColumn).Offset(i / 2).Resize(rowsToAdd).EntireRow.Insert If Err.Number < 0 Then MsgBox Err.Description, vbCritical End If i = 1 End If Next iRow End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Checking a date/number between two others | Excel Discussion (Misc queries) | |||
number checking | Excel Discussion (Misc queries) | |||
number checking | Excel Discussion (Misc queries) | |||
Checking cell for Number | New Users to Excel | |||
Checking if value is a number | Excel Programming |