# Help with Mod and / Functions in VBA

#### pokeManiac

##### New Member
Hi,

I need help with writing the Mod and / functions in VBA in a different way. I read in another thread that these two intrinsically produce results of the Long data type. But I need more than that. This is my convertToHex function which takes in as argument a decimal number:

result = ""
while decNum > 16
result = choose(decNum Mod 16 + 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F") & result
decNum = Int(decNum / 16)
wend
convertToHex = choose(decNum + 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F") & result

It works fine for a hexadecimal value with seven digits. But when the computation produces an eighth, I get an overflow error.

Help!

### Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

#### Darren Bartrup

##### Well-known Member
Hi and welcome to the board,

Couldn't you just use HEX(123456) or EVALUATE("DEC2HEX(123456)") rather than write a function?

#### pokeManiac

##### New Member
Hahahahaha! I didn't know there was a HEX function in vba. That would certainly simplify everything. I would just like to know though how EVALUATE works. I tried looking it up on Excel's help tool but nothing came up.

#### pokeManiac

##### New Member
I tried using the HEX function but I'm still getting an overflow error. This is how my statement now looks like:

doXorCalc = Hex(convertToDec(hexValue1) Xor convertToDec(hexValue2))

where hexValue1 and hexValue2 are string representations of the hexadecimal values I want to do the XOR operation on and doXorCalc is the function returning the result. I even tried converting the data type to DECIMAL with the CDEC function after getting the decimal values but it still would not work.

What am I doing wrong here?

Replies
1
Views
103
Replies
7
Views
320
Replies
2
Views
179
Replies
3
Views
139
Replies
0
Views
147

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,151,972
Messages
5,767,401
Members
425,410
Latest member
SmittyT

### 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.

### Which adblocker are you using?

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

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