Is it possible to formatting bold in excel formula? - excel-formula

format sample
Here I want to add text a1+b1+c1, But I want to bold b1 text like command module will be bold.
Is it possible to bold this word.
date formatting
Is it possible to bold date. suppose Date: 08/01/2017

No, you can't. Excel doesn't provide such functionality to apply rich text formatting to part of the formula.
But you can possibly insert a Text Box over the result cell to achieve this. Here is a link that you can read: Formatting part of a formula

Since you can apply rich text formatting to the cells that contain the formula, why not use more than 1 cell and eliminate the display of line between them so the 2 cells look like 1. Then put the word "Date:" in the first cell flush right margin and in the cell next to it, put the formula to gather the date, formatting the cell to flush left margin, and bold that cell.

You cannot format text to italic, but you could change the basic latin letters to corresponding italic unicode characters:
Function ITALIC(orig As String) As String
Dim result As String
Dim c As Long
result = ""
For i = 1 To Len(orig)
c = WorksheetFunction.Unicode(Mid(orig, i, 1))
If c > 64 And c < 91 Then c = c + 120263
If c > 64 And c < 123 Then c = c + 120257
result = result & WorksheetFunction.Unichar(c)
Next i
ITALIC = result
End Function
You may change the text to many other forms as well.
https://lingojam.com/ItalicTextGenerator

Related

Check id every value in ";" separated string exists on a LOV list using just Excel formulas

In a cell I have a multi value separated by semicolon like this:
Red;Blue;Green
I need to compare if each of those values exist on a list:
Black
Orange
Green
Blue
Red
I think it should be an array formula, but I have no idea how to set it.
Is it even possible?
Regards
Michał
You've not mentioned what output you are looking for. Below are the two possible solution.
1. If you are looking for the count of words in a cell from the list use following formula:
=SUMPRODUCT(ISNUMBER(FIND($E$2:$E$6,$A2))*1)
2. If you want words in the cell that are in the list to be displayed in separate columns, use the following array formula
=IFERROR(INDEX($J$2:$J$6,SMALL(IF(ISNUMBER(FIND($J$2:$J$6,$A2)),ROW($J$2:$J$6)-ROW($J$1)),COLUMNS($A1:A1))),"")
Drag/copy above formula across and down as required.
Being an array formula you'll have to commit this formula by pressing Ctrl+Shift+Enter.
You can write this UDF and use it as a formula. Wasn't sure what output is required. This UDF gives number of items that match in the list.
Parameters:
myValue - the cell that contains multi value separated by semicolon
listRange - Range that has the list to check against. Should be a single column list
Function checkList(myValue As Range, listRange As Range) As Integer
Dim t As Variant
t = Split(myValue.Value, ";")
Dim c As Integer
c = 0
For i = LBound(t) To UBound(t)
For j = 1 To listRange.Rows.Count
If (t(i) = listRange(j, 1)) Then
c = c + 1
End If
Next j
Next i
checkList = c
End Function
Since you want to do this only with excel formulas, the input string has to be split to multiple cells before comparing it with the list.
If your input string is in A1, use the below formula and drag it right to split them based on the delimiter ;.
=TRIM(MID(SUBSTITUTE($A1,";",REPT(" ",999)),1+((COLUMN(A1)-1)*999),999))
Assuming your list is in column G, use the below formula which counts the strings Red, Blue and Green in your list and returns Found or Not found.
in C2,
=IF(COUNTIF($G:$G,C1),"Found","Not found")
Hope this helps.

How to have excel recognize zero as a string?

I need to put data validation on a range of cells so that you can enter no more and no less than 9 characters in those cells. The problem is that SOMETIMES those 9 characters will be all number ... and that "number string" will start with a zero ... e.g. 012345678. Excel will remove the zero, as it recognizes that string as a number and my validation kicks in saying that I need to enter 9 characters into that field.
Any ideas?
Format the range of cells as Text. This will prevent Excel from trimming leading zeroes.
=TEXT(Cellwithnumber,"000000000")
Normally, if you format a range as text prior to typing in data (by right-clicking → format cells) or with something like
Dim c As Object
For Each c In Selection.Cells
c.NumberFormat = "#"
Next c
or
ActiveSheet.Cells.NumberFormat = "#"
Excel wont cut the leading zeroes.
If other users are using your sheet, you could protect the cell formats, so they don't accidentally change it back to numbers by, say, pasting data in with formats.
You could create a new cell and enter them as text formulas. Say the value you want to get the 0 from is in A1, enter your formula in a cell:
=TEXT(A1,"000000000")
That will show the leading 0.
If you want to use VBA:
rngTarget.NumberFormat = "#" ' rngTarget is a Range, can be e.g. ActiveCell or ActiveSheet.Cells(1, 2) or ActiveSheet.Range("B8")

Do math on cells also contaning text in EXCEL

I have a range of cells which I want to do some math on. But I also want those cells to contain some text.
For instance I want the sum of A1 and B1 where A1 contains the number 10 and "z001" and B1 contains the number 20 and "Z004".
Then I want the formula to ignore the text, and just come up with 30.
Is this possible?
For a quick solution, type "=Left(A1, 2) + Left(B1, 2)" into C1. Drag this equation down the rest of your range and you should get the results you want, provided the numbers you are adding are all 2 digits.
You can also use VBA if you need to run the same equation on multiple cells.
If you can get the same results by just removing the letters, try:
For i = 58 To 127
'Change out str with the variable name you have assigned to your cell value.
str = Replace(str, Chr(i), "")
Next i
58 and 127 represent the first and last positions in a range of characters on the Ascii table that are not numerals http://www.asciitable.com/
If you just want to include the first two numbers of each cell in your equation and ignore the "Z00#", you can try:
strLeft = Left(str, 2)
This will reduce your string down to the first two characters of each cell.
You can look here for other ways to remove characters you don't want.
http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=269:excel-vba-string-functions-left-right-mid-len-replace-instr-instrrev&catid=79&Itemid=475
Here is in example of how you would implement something like this with simple addition.
Dim a as range
Dim b as range
Dim aLeft as integer
Dim bLeft as integer
Dim cleft as integer
a = Worksheets("WorksheetName").Cells(A1).Value
b = Worksheets("WorksheetName").Cells(B1).Value
aLeft = Left(a, 2)
bLeft = Left(b, 2)
cLeft = aLeft + bLeft
Worksheets("WorksheetName").Cells(C1).Value = cLeft
This would add the first two digits of cells A1 and B1 then display the result in C1.
As I see it, you have 2 options:
Search for the number within each cell and sum it up (see below).
Split the columns to have 1 column of numbers and one of codes (e.g.
"z001"). See on the "Data" tab on the ribbon and click "Text to
Columns" on the Data Tools group.
The first option would be the quickest and more straightforward. You need to make a third column where the sum will be and then use, for example, the function LEFT. This function allows you to retrieve characters from a cell. See example below:
To get "30" I have used the following formula on C2:
=LEFT(A2,2)+LEFT(B2,2)
Note this is not ideal since this formula is looking for 2 characters every time. If you have a scenario with the following code "5z005" it won't work because it will try to sum "5z" as if it was a number. In that case you're better off finding a pattern (code = "number" "z" "number") and splitting the columns as I said on option 2.

display inside a column the number from a string

I have one column (B) ( over 3k cells ):
TestUrl
__________________________________
http://www.testing.eu/test123.html
http://www.testing.eu/test154.html
http://www.testing.eu/test983.html
.. and so on ...
I want in column C, to get only the numbers:
Numbers
__________
123
154
983
..and so on..
How can I achieve this?
using an array formula..
assuming your data starts at B2.
type this in the formula bar on C2.
Then instead of pressing ENTER, press CTRL+SHIFT+ENTER.
Then just drag down to copy to other cells below.
=SUMPRODUCT(MID(0&B2,LARGE(INDEX(ISNUMBER(--MID(B2,ROW($1:$50),1))* ROW($1:$50),0),ROW($1:$50))+1,1)*10^ROW($1:$50)/10)
change the B2 in the formula if your data starts somwhere else. Just make sure to press CTRL+SHIFT+ENTER instead of ENTER after changing.
got this from:
http://www.extendoffice.com/documents/excel/1622-excel-extract-number-from-string.html
Using formula in column B:
=MID(A1,LEN("http://www.testing.eu/test") + 1, LEN(A1) - LEN(".html") - LEN("http://www.testing.eu/test"))
Using VBA and Regex:
Sub GetNumberFromURL()
Dim regEx As Object, matches As Object, cl As Range
Set regEx = CreateObject("vbscript.regexp")
regEx.Pattern = "([0-9]+)"
For Each cl In Range("A1:A10") //Update to suit your needs
Set matches = regEx.Execute(cl)
cl.Offset(0, 1) = matches.Item(0)
Next
End Sub
Copy the B column data in notepad and replace http://www.testing.eu/test by empty string and then do same thing with .html. After replacing/removing these string paste the notepad content in column C

how to break a string in to substring in excel?

original column is like:
0.45::rafas::4.0::0.0::0.9
0.35::rasaf::4.0::110.0::1.0
and i would like to break the string in to the following (:: as separator) in Excel
col1 col2 col3 col4 col5
0.45::rafas::4.0::0.0::0.9 0.45 rafas 4.0 0.0 0.9
0.35::rasaf::4.0::110.0::1.0 0.35 rasaf 4.0 110 1.0
Please help.
This page explains how to do just that using the "Text to Columns" function.
Copied for your convenience:
Highlight all of your cells with the data.
Select The Topmost Cell In The Column, E.G. A1 Hold CTRL+SHIFT And
Then Press The Down Arrow. OK, Once We've Done That, Go To "Data" Menu
And Select "Text To Columns". On The Text To Columns Window, Select
"Delimited" And Then Hit "Next". In The Following Window, Choose
"Other" For Type Of Delimiter And Use The Minus/Hyphen Sign - Hit
Finish.
Now you will have two columns, from your example, the first column
will contain data like "Animals" and the other column will contain the
data " House of The Rising Sun". (note the SPACE in front of "House")
To get rid of that SPACE we're going to use the TRIM function.
In cell C1 (or the column to the right of the song titles) type in
this formula.
=TRIM(B1)
Then double-click on that little black box on the excel cursor to copy
the formula down the whole range. Any spaces at the Start or end of
the text string will be removed.
If you wanted to do it with forumlae rather than the "text to columns" functions you could use:
Assuming string in A1
in B1: =FIND("::",$A1)
in C1: =FIND("::",$A1,B1+1)
Then copy C1 over D1:E1
in F1: =MID($A1,1,B1-1)
in G1: =MID($A1,B1+2,C1-B1-2)
Then copy G1 over H1:I1
And finally
in J1: =MID($A1,E1+2,LEN($A1)-E1-1)
The results of the split will be in F1:J1. You can always hide columns B:E as they are just internal to the splitting. This can then be done on as many rows as you need and if the value in A1 is update all other values will be changed. However, it is on a fixed number of columns but can easily be expanded if needed.
Excel (and OpenOffice) have a functionality to split Text into Columns. Highlight all the columns that conform to this schema, then go to the Data menu, and select "Text to Columns". Used a delimited separator and specify it as ":" while treating consecutive delimitors as one.
Here is a very simple way to extract the 5th character from the left from a text string in Excel:
Suppose the character string ABCDEFGHIJ is stored in cell A1 in an Excel Spreadsheet, then the following formula
=RIGHT(LEFT(A1,5),1)
produces the 5th character from the left in the string, namely “E”.
If you would like a simple function, you can use the following VBA code.
Function SplitTextToNum(rngInput As Range, sepString As String)
Dim CallerRows As Long, CallerCols As Long, DimLimit As Long
Dim outvar As Variant
outvar = Split(rngInput.Value, sepString, -1, vbBinaryCompare)
If Application.Caller.Rows.Count > 1 Then
SplitTextToNum = Application.Transpose(outvar)
Else
SplitTextToNum = outvar
End If
End Function
You can use Ctrl+Shift+Enter over a range of cells after entering the formula referring to the cell in which you have the string that you need to be split up.

Resources