If Variable is Odd then

ktkelly_1

New Member
Joined
Jun 13, 2019
Messages
17
I am having trouble writing a code to recognize if a number is odd or not and then determining what to do from there... It keeps pooping up with an "object required" error. Please let me know how I can fix it, or if you have ever come across this problem.

Here is my code

STNDRD=17

If STNDRDR Is IsOdd Then
ActiveCell.Offset(0, 0).Select
Else
ActiveCell.Offset(0, -1).Select
End If

 
Just note that may not work properly if the possibility of decimals exists.
It would incorrectly evaluate to TRUE for a value like 1.6.
Actually, if Integer numbers are not guaranteed, all of the code shown so far would fail under certain circumstances. If not guaranteed, we would have to add a test to rule out floating point values. My code examples could be changed like so...

If Stndrd Like "*[02468]" And Stndrd = Int(Stndrd) Then ActiveCell.Offset(0, -1).Select

or...

ActiveCell.Offset(0, Stndrd Like "*[02468]" And Stndrd = Int(Stndrd)).Select
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,214,669
Messages
6,120,828
Members
448,990
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top