Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Mod function not working right?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DMB - 22 Jan 2006 22:31 GMT
this formula is giving me an error. I need the remainder. Am I doing this
wrong?

26 Mod 3
Tom Ogilvy - 22 Jan 2006 22:55 GMT
from the immediate window:

? 26 Mod 3
2

seems to work fine.

Signature

Regards,
Tom Ogilvy

> this formula is giving me an error. I need the remainder. Am I doing this
> wrong?
>
> 26 Mod 3
JE McGimpsey - 22 Jan 2006 23:01 GMT
Hard to know if you're doing it wrong, since you don't say what you're
trying to do.

Mod is an operator, so it only makes sense in an assignment statement.
For instance:

  a = 26 Mod 3

returns 2 to the variable a.

A bare

   26 Mod 3

doesn't make sense - it's like putting the number 2 as a statement.

> this formula is giving me an error. I need the remainder. Am I doing this
> wrong?
>
> 26 Mod 3
bigwheel - 22 Jan 2006 23:03 GMT
Try =MOD(26,3)

> this formula is giving me an error. I need the remainder. Am I doing this
> wrong?
>
> 26 Mod 3
Tim Williams - 23 Jan 2006 00:17 GMT
What answer are you expecting?

Tim

> this formula is giving me an error. I need the remainder. Am I doing this
> wrong?
>
> 26 Mod 3
DMB - 23 Jan 2006 14:17 GMT
Function LumberLabel(width As Range, height As Range, material As Range,
spacing As Range) As String
   
   Dim myWidth As String
   Dim myHeight As String
   Dim myMaterial As String
   Dim mySpacing As String
   myWidth = width
   myHeight = height
   myMaterial = material
   mySpacing = spacing
   
   'Material type: DF #2, DF#1, PSL, ect.
   
   'Add spacing ie @ 16" O.C. , @ 25" O.C.
   If mySpacing <> 0 And mySpacing <> "" Then mySpacing = " @ " & mySpacing
& " in oc"
   
   'Lumber sizing
   Dim x As Integer
   'x = width Mod 0.5
   
   Dim aWidth As Double
   aWidth = Round(myWidth)
   If ((aWidth / 2) - (aWidth \ 2)) <> 0 Then
       LumberLabel = "1. Will not work (myWidth / 2) = " & (myWidth / 2) &
"  and myWidth \ 2 = " & (myWidth \ 2)
   'ElseIf x <> 0 Then
       LumberLabel = "2. x <> 0 = " & width Mod 0.5
   Else
       LumberLabel = myWidth & " x " & myHeight & myMaterial & mySpacing
   End If
      'This is giving me the error
       'width Mod 0.5
      'and this
        LumberLabel = "2. = " & 19.6 Mod 3.2
       
      'A = 19 Mod 6.7

End Function
Tom Ogilvy - 23 Jan 2006 16:47 GMT
? 19.6 Mod 3.2
2

the equivalent of   20 mod 3

which is the expected behavior as stated in help on the MOD function.   So
you still didn't answer what you expect?

width mod 0.5   gives me a divide by zero, so 0.5 is rounded down to 0 I
suspect. (it is probably stored as .49999999999)

I don't think the mod operator will work for you.
Signature

Regards,
Tom Ogilvy

> Function LumberLabel(width As Range, height As Range, material As Range,
> spacing As Range) As String
[quoted text clipped - 36 lines]
>
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.