Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA is odd function

Is there a function in VBA that is equivalent to the isodd function in
Excel? If one of my text values is odd I need to print a certain range, if
even another range. I am using Excel 2000.
Bob


  #2   Report Post  
Posted to microsoft.public.excel.programming
Dyl Dyl is offline
external usenet poster
 
Posts: 10
Default VBA is odd function

You could use the mod operator which finds the remainder. So if a
number is divided by 2 and the remainder is 1, then it is odd. If a
number is divided by 2 and the remainder is 0, then it is even.

Try this:

Temp = Val("Text") <--Put text in number format

If Temp Mod 2 = 1 Then <--Odd
......

Else '<---Even
........

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA is odd function

Hi Bob,

If n Mod 2 = 1 Then
' n is odd


---
Regards,
Norman


"Robert Dieckmann" wrote in message
...
Is there a function in VBA that is equivalent to the isodd function in
Excel? If one of my text values is odd I need to print a certain range,
if even another range. I am using Excel 2000.
Bob




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA is odd function

I am still having some trouble implementing this.

I use a text box on a form to enter a value into the spreadsheet using the
control source- txtHt.value = 25 for example.

the following code prints out A53:AI104 like I want it to.

If chkBld.Value = True Then
Odd = Val("25")
If Odd Mod 2 = 1 Then
Sheets("Buildup").Select
Range("A53:AI104").Select
Selection.PrintOut Copies:=1, Collate:=True
Else
Sheets("Buildup").Select
Range("A1:AI52").Select
Selection.PrintOut Copies:=1, Collate:=True
End If
End If

These always print out A1:AI52 (the rest of the code being the same)
Odd = Val(txtHt)
Odd = Val("txtHt")

These give me an object required error
Odd = Val(txtHt.Value)
Odd = txtHt.Value

What I am I missing?
Bob

"Dyl" wrote in message
ups.com...
You could use the mod operator which finds the remainder. So if a
number is divided by 2 and the remainder is 1, then it is odd. If a
number is divided by 2 and the remainder is 0, then it is even.

Try this:

Temp = Val("Text") <--Put text in number format

If Temp Mod 2 = 1 Then <--Odd
.....

Else '<---Even
.......



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default VBA is odd function


Robert Dieckmann wrote:
I am still having some trouble implementing this.

I use a text box on a form to enter a value into the spreadsheet using the
control source- txtHt.value = 25 for example.

the following code prints out A53:AI104 like I want it to.

If chkBld.Value = True Then
Odd = Val("25")
If Odd Mod 2 = 1 Then
Sheets("Buildup").Select
Range("A53:AI104").Select
Selection.PrintOut Copies:=1, Collate:=True
Else
Sheets("Buildup").Select
Range("A1:AI52").Select
Selection.PrintOut Copies:=1, Collate:=True
End If
End If

These always print out A1:AI52 (the rest of the code being the same)
Odd = Val(txtHt)
Odd = Val("txtHt")

These give me an object required error
Odd = Val(txtHt.Value)
Odd = txtHt.Value

What I am I missing?
Bob


Hi,

The only way I can figure out how you are getting an "object required"
error at the line Odd = Val(txtHt.Value) is if you are not using option
explicit and if you have mistyped the name of the textbox. Check the
name in the properties of the textbox. Val wouldn't throw such an error
but txtHt.value might.

Hope that helps

-John Coleman

-John Coleman

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
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 09:54 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"