noob question on UDFs

jrg24

New Member
Joined
Aug 6, 2010
Messages
49
Hi all.

I have found a UDF online that does what I need it to do, but I am not sure how to make this function available on all workbooks I open. I know the workbooks will have to be maco enabled, but even upon opening a macro enabled workbook my UDF will not work. Will I have to copy and paste the data into the workbook containing the UDF everytime I want to use the function (or add the code for the UDF to each workbook) or is there a way to make it work in all macro enabled workbooks?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Store the UDF in the personal macro workbook, then it's available all the time working in Excel.
 
Upvote 0
Store the UDF in the personal macro workbook, then it's available all the time working in Excel.

I just tried this and it is not working. I am using excel 2010. I read an article somewhere that made it seem that only macros will work from the personal workbook. I tried saving it as an addin, and it only gave an approximately close answer with information in decimal places beyond the hundreths place. All data in the workbook i tested does not have any information beyon the hundreths place, and I have manually checked the data and know the correct sum.. I have verified that the VBA code is in the personal workbook.

My UDF is designed to find the sum of all bold formatted numbers (formatted as accounting) in a given column of data. The code follows:

Public Function SumBold(rngSumRange As Range) As Single
Dim rngCell As Range
For Each rngCell In rngSumRange
If IsNumeric(rngCell.Value) Then
If rngCell.Font.Bold = True Then
SumBold = SumBold + rngCell.Value
End If
End If
Next rngCell
End Function

Would creating a real addin be a better option? I know a little C# programming, but I would have to learn some more to make this happen. Does anyone have any tips on learning the creation of addins? This is just the first of many projects that I will be working on to help automate my work. Thanks for your time.
 
Upvote 0
Hi

I think your problem is because the UDF you posted uses the Single data type - change it to Double and it should be ok. I cannot explain the exact technical reason in this instance but it's basically due to the fact that computers cannot represent decimal numbers precisely using binary which results in "incorrect" results in some instances - here is a brief explanation: http://msdn.microsoft.com/en-us/library/system.single(VS.85).aspx

If you stick with doubles then you're using the same data type as Excel uses internally so you will be less likely to run into problems.

HTH
DK
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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