View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Robert Dieckmann Robert Dieckmann is offline
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
.......