functions vba

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Functions in VBA

Functions in VBA

resolvedResolved · Medium Priority · Version 2003

William has attended:
Excel VBA Intro Intermediate course
Excel Advanced course

Functions in VBA

Could you please tell me if it is possible to write functions in Visual Basic which then display the formula script in Excel?

I think this would be useful for 2 reasons:

1) The user can see the formula and understand how the values have been calculated by selecting a cell.

2) Cell values will be udpated if the source data changes without having to rerun the function.

Many thanks for your help

RE: Functions in VBA

Hi William

Thanks for your question

You can add a formula programmatically using the formulaR1C1 method of the range object

The following places a sum function that sums a range specified in terms of its relative position to the formula

Worksheets("Sheet1").Range("d10").FormulaR1C1 = "=SUM(R[-12]C[-2]:R[-6]C[-1])"


Regards

Stephen

Thu 5 Nov 2009: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Wrapping Text in a Cell in an Excel 2010 Workbook

When you have a lot of text you want to put in a particular cell but you can't decrease the font size to fit because the text will then become ineligible, then manually wrap the text in a cell by simply pressing ALT+ENTER.

View all Excel hints and tips


Server loaded in 0.1 secs.