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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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