Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking a date/number between two others [email protected] Excel Discussion (Misc queries) 6 March 31st 09 12:01 AM
number checking diam Excel Discussion (Misc queries) 0 November 29th 06 05:46 PM
number checking diam Excel Discussion (Misc queries) 0 November 29th 06 05:35 PM
Checking cell for Number Lee New Users to Excel 2 October 11th 05 09:23 PM
Checking if value is a number jonx - ExcelForums.com Excel Programming 2 September 24th 04 08:34 PM


All times are GMT +1. The time now is 08:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"