excel can VBA UDF output formatted text? - string

Is there a way to return a string from an UDF formatted? For example I would like first two words to be bold, the rest not.

Functions are not allowed to alter the formatting of the worksheet. That being said, Sub() can and you can easily write a Sub routine that does this - it just means you'll have to run the macro (like using F8) instead of entering it as a formula inside a cell.

Sorry, but you can't apply rich text formatting to the result of a formula.

Related

How to make Excel represent cell value as it is instead of formula?

I have a large excel file (more 5000 records), and some of the arbitrary cells show its value as a result returned from formula instead of the text value. I can fix it by remove leading equal operator (this is the final result) but I can't manually line by line looking tirelessly through my excel file to detect all kind cells. Is there any solution? Thank you so much!
Updated:
I need something like that:
In the ribbon tab Formulas turn on Show formulas button and you will see all possible formulas.
Use FORMULATEXT() function.
=FORMULATEXT(A2)

Using excel vba, how to write a formula in a cell

In Excel, A1 is equal to =B1/ BDP(C11&”Corp”, “ds036”)
Which BDP(Corp, ds036) is a function and parameters from Bloomberg.
How to use Excel VBA for this formula?
I was trying different ways in VBA to solve my point. One of them is like the line below,
Cells(1,1)=“B1/ BDP(C11&”Corp”, “ds036”)”
An other way I tried, to simplify,
For i=1 to10
Cells(i,1)=“Cells(i,2)/ BDP(cells(i,3)&”Corp”, “ds036”)”
Next
Also, if it can access directly to BDP function. That will be perfect!
try:
Cells(1,1).Formula = "=B1/ BDP(C11&""Corp"", ""ds036"")"
Note:
I used a different flavor of double quote
I doubled-up on the double quotes
Does this do what you want?
Range("A1:A10").Formula = "=B1/BDP(C3&""Corp"",""ds036"")"
If you assign a formula to a multi-cell range, I think Excel will automatically adjust relative cell references for subsequent rows/columns - similar to CTRL+D or dragging down.
This means you don't need to loop through each row and re-construct the formula string for each loop iteration.

Change excel formula syntax using indirect function

I want to change formula syntax basis user selection in excel drop down. For example: replace Small with Large in =Small(F3:F16,1), if user selects Large from drop down given.
I tried ="="&INDIRECT("H2")&"(F5:F16,1)" where H2 is the drop down containing Small and Large. but its not working.
Indirect can only reference range, and it cannot change formula part. you should use If/choose statement instead.
=IF(H2="Small",SMALL(F3:F16,1),LARGE(F3:F16,1))
Instead of actually using the text itself as a function, I would just use an IF statement, i.e. something like:
= IF(H2="Large",LARGE(F5:F16,1),SMALL(F3:F16,1))
Another option is to use excel functions which use numbers to refer to functions like AGGREGATE or SUBTOTAL, e.g.
=AGGREGATE(IF(H2="LARGE",4,5),4,F3:F16)

Evaluate an expression as a formula in Excel

I have created an expression using "&" to concatenate different cells, I created this:
=INDEX((Data_sheet!A1:M20440;Data_sheet!A20441:M40880;Data_sheet!A40881:M61320);20;5;D2)
Now, I have the expression that is a formula, but it is not evaluated as a formula when I paste it, I can see the whole expression in the cell, but I want to get is the value that is behind evaluating that formula. I want to know how to make it to evaluate as a formula (because I will have thousands of this expressions)
My guess is that you would have created the INDEX formula in excel using multiple other formulas.
Once you have created the formulas, copy all the formulas and paste it in a txt file. Then, copy all the formulas from txt file and paste it again in the excel where you want the formulas to perform. This is the simplest way of doing this without creating any macros or additional formulas
See this question for solutions:
How to turn a string formula into a "real" formula
In particular, also note the answer about Excel's hidden EVALUATE function, that can only be accessed after defining a name to use it.
https://www.vertex42.com/ExcelArticles/evaluate-function.html

Can Excel Conditional Formatting use UDFs in the condition?

I have a cell in Excel that I want to format differently based on a user defined formula (UDF) - my formula tests whether there is a formula in the cell...
I am trying to use conditional formatting with my UDF to format the cell - but it does not seem to be working.
My condition is this:
="isManualPrice(R22C12)"
I tried without the quotes, but get the error
You cannot use references to other
worksheets or workbooks for
Conditional Formatting criteria
Perhaps the issue relates to my UDF being defined in a separate macro workbook and not my main workbook...
I see its mentioned in this blog entry from 2005, but only in passing...
Thanks in advance.
Chris
Yes, it can.
Your problem is simply that you've got quotes in there. You need to choose "Formula Is" from the drop-down, and then your formula should be
=isManualPrice(R22C12)
...with no quotes.
(I'm more used to A1 notation rather than R1C1 notation but I assume that'll work just as well).

Resources