# 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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

#### 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
3
Views
33
Replies
12
Views
299
Replies
1
Views
174
Replies
6
Views
87
Replies
2
Views
136

Threads
1,186,169
Messages
5,956,342
Members
438,247
Latest member
UZev

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

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