create hyperlink using cell value and some additional text in excel - excel

I have excel sheet containing column with values such as
BANDHANBNK
SRF
SRTRANSFIN
L&TFH
IBULHSGFIN
FEDERALBNK
PNB
PEL
VOLTAS
I want to create hyperlink for each of this, url can be created as
https://in.tradingview.com/chart/?symbol=NSE:ACC1!
so I need to concatenate
https://in.tradingview.com/chart/?symbol=NSE: + cell value + 1!
doing this manually is too much work, is there any simpler way to do this?
one more thing is if cell value contains & or - it should be converted to underscore.

Use following formula. Here simply concatenating cell value with URL then concatenate 1!. Use Hyperlink() formula to make hyperlink.
=HYPERLINK("https://in.tradingview.com/chart/?symbol=NSE:" & A1 & "1!",A1)
To replace & and - by underscore _ use below SUBSTITUTE() formula.
=SUBSTITUTE(SUBSTITUTE(A1,"&","_"),"-","_")

this worked for me.
=HYPERLINK("https://in.tradingview.com/chart/?symbol=NSE:" & SUBSTITUTE(SUBSTITUTE(E2,"&","_"),"-","_") & "1!",E2)

Related

Excel VBA conditional formatting based on another column and cell value [duplicate]

I've got an Excel spreadsheet, with a Macro, that inserts a conditional formatting, like this:
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=UND($A3=""" & lastName & """; $B3=""" & firstName & """)"
As you can see, I've used the German formula for "AND" (i.e. "UND"), and obviously, this code doesn't work as soon as I use it on a French or English version of Excel.
Usually formulas are localized automatically, but how can I insert a formula during run-time that will work on ALL versions?
Ok, thanks for helping me with this, you've helped me crack this one.
It is indeed not possible to just use English. One can use English when operating on a formula, eg. by setting coding Range("A1").formula="AND(TRUE)", but this does not work with FormatConditions.
My solution is a function that writes a formula temporarily to a cell, reads it through the FormulaLocal property, and returns the localized formula, like so:
Function GetLocalizedFormula(formula As String)
' returns the English formula from the parameter in the local format
Dim temporary As String
temporary = Range("A1").formula
Range("A1").formula = formula
Dim result As String
result = Range("A1").FormulaLocal
Range("A1").formula = temporary
GetLocalizedFormula = result
End Function
The returned formula can be used on FormatConditions, which will be re-localized or un-localized when the document is later opened on a different-language version of Excel.
I just found a very elegant solution to the problem in a German Excel forum. This doesn't write to a dummy cell but rather uses a temporary named range. I used the original idea (credit to bst) to write a translating function for both directions.
Convert localized formula to English formula:
Public Function TranslateFormula_LocalToGeneric(ByVal iFormula As String) As String
Names.Add "temporaryFormula", RefersToLocal:=iFormula
TranslateFormula_LocalToGeneric = Names("temporaryFormula").RefersTo
Names("temporaryFormula").Delete
End Function
Convert English formula to localized formula:
Public Function TranslateFormula_GenericToLocal(ByVal iFormula As String) As String
Names.Add "temporaryFormula", RefersTo:=iFormula
TranslateFormula_GenericToLocal = Names("temporaryFormula").RefersToLocal
Names("temporaryFormula").Delete
End Function
This is very handy if you need to deal with formulas in conditional formatting, since these formulas are always stored as localized formulas (but you could need their generic version, e.g. to use Application.Evaluate(genericFormula)).
Store (a trivial version of) the formula in a (hidden) cell in your workbook.
Then when you open the workbook that formula will be translated automatically by excel for the user.
Now you just have to dissect this formula in your script (find the opening bracket "(" and take the past left of that:
Use something like:
strLocalizedFormula = Mid(strYourFormula, 2, InStr(1, strYourFormula, "(") - 2)
where strYourFormula will be a copy from the formula from your worksheet.
I hope this works as I only use an English environment.
Also from reading this:
http://vantedbits.blogspot.nl/2010/10/excel-vba-tip-translate-formulas.html
I am thinking you should (only) be able to use the english version of a cell formula from VBA.
Maybe try this (untested as I only have English version insatlled)
Write your international version of the formula to an out of the way cell using Range.Formula . Then read it back from Range.FormulaLocal, and write that string to the FormatConditions
I know this thread is ages old, and someone may have found an elegant solution, but I just had the same problem where I needed to apply conditional formatting without modifying the sheet, creating temporary cell contents or named ranges. All users use English language versions of Excel, so the functions used in the formulas are the same, but the regional settings vary by location, and therefore also the parameter separater; In Norwegian, it's ";" instead of ",", much like the rest of Europe, I guess.
For example, I needed to automatically create conditional formatting, using Excel formula for the following criterion:
.FormatConditions.Add xlExpression, Formula1:="=AND(ISNUMBER(B" & I & "),B" & I & ">=" & Ul1 & ")"
Where "Ul1" is a value defined in a previous step, and it's not important for the solution.
However, I needed to be able to run this on computers with both Norwegian and English settings
I and found a very short and simple solution from Andrew Pulsom here: https://www.mrexcel.com/board/threads/french-vba-vs-english-vba.729570/. He just made the parameter separator into a variable:
If Application.International(xlDecimalSeparator) = "," Then
Sep = ";"
Else
Sep = ","
End If
Cl1 = "=AND(ISNUMBER(B" & I & ")" & Sep & "B" & I & "<" & Ul1 & ")"
Worked like a charm for me :)
I know that this only solves part of the problem, but I assume that this could apply to many international companies which use English Office installations with local regional settings.
Thanks everyone! I found the post very useful.
My solution is a combination of others, I add it in case somebody finds it useful.
Dim tempform As String
Dim strlocalform1 As String
Dim strlocalform2 As String
' Get formula stored in WorksheetA Cell O1 =IFERROR(a,b)
tempform = Worksheets("Sheet").Range("O1").Formula
' Extract from the formula IFERROR statement in local language.
strlocalform1 = Mid(tempform, 2, InStr(1, tempform, "(") - 1)
' Extract from the formula separator , (comma) in local settings.
strlocalform2 = Mid(tempform, InStr(1, tempform, "a") + 1, 1)
' Add formula in local language to desired field.
pvt.CalculatedFields.Add Name:="NewField", Formula:="=" & strlocalform1 & "FORMULA" & strlocalform2 & ")"
Hope this helps!
Please refer to the link for more explanation: https://bettersolutions.com/csharp/excel-interop/locale-culture.htm
CultureInfo baseCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo(xlapp.LanguageSettings.LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI));
// do something
System.Threading.Thread.CurrentThread.CurrentCulture = baseCulture;

How to change string name to specific string name?

I want Excel (or Linux command) to change the string of values.
From:
e.g. column A
IN_EMAIL.201_101300_180403_131131_6160_5593
To:
e.g. column B
EMAIL.201_101300_0_180403_131131616_0000_5593
So:
Remove "IN_"
Add "0_" after 20th character
Remove "_" after 33rd character
Add "_000" after 37th character
I've got two formulas. How can I nest them into one?
=REPLACE(REPLACE(A4;1;3;"");18;0;"0_")
=REPLACE(REPLACE(B4;33;1;"");36;0;"_000")
It is solved,
=REPLACE(REPLACE(REPLACE(REPLACE(A11;1;3;"");18;0;"0_");33;1;"");36;0;"_000")
If you want to combine these two formulas:
=REPLACE(REPLACE(A4;1;3;"");18;0;"0_")
=REPLACE(REPLACE(B4;33;1;"");36;0;"_000")
Just replace B4 with the first formula
=REPLACE(REPLACE(REPLACE(REPLACE(A4;1;3;"");18;0;"0_");33;1;"");36;0;"_000")
Alternatively you could use the following formula that might be more obvious:
=MID(A5;4;17) & "0_" & MID(A5;21;13) & MID(A5;35;3) & "_000" & RIGHT(A5;6)

excel function to combine cells into single line of text?

I'm new to stack overflow so I apologize if this is a horrendously stupid question. I am wondering if there is a function or way to code a function in excel that will combine a column of cells with plain text and convert them into one cell with the text on a single line? Specifically I want to convert a column of random numbers into a single line of text and insert SPACE+AND+SPACE between them.
Ex.
15133484
12345188
12345888
to
15133484 AND 12345188 AND 12345888
Currently I am copying and pasting all this information into google and then into Word and using find/replace and it is taking forever everytime. If it is possible to just get Excel to do this for me that would be amazing.
Thanks!
If you have Office 365 Excel use TEXTJOIN():
=TEXTJOIN(" AND ",TRUE,A:A)
otherwise one would have to use:
=A1 & " AND " & A2 & " AND " & A3
Or one can use a helper column, B1 put:
=A1
put this in B2 and copy down:
=IF(A2<>"",B1 & " AND " & A2,B1)
And grab the last cell in column B.
A little late, but still:
Reference here
Step 1:
=concatenate(transpose(rngBeg:rngEnd & " AND "))
Step 2:
highlight the transpose statement and then press F9, which substitutes the actual values for the formula.
Step 3:
Remove the curly braces, { }, from the formula. The cell will display the range of reference cells combined with whatever separator chosen after the ampersand sign.
Not a "live" formula, but still far easier than manually concatenating a range of values.
Press ALT+F11 to open Microsoft Visual Basic for Applications,
Insert-> Module
Paste this:
Function Combine(WorkRng As Range, Optional Sign As String = " AND ") As String
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
If Rng.Text <> "," Then
OutStr = OutStr & Rng.Text & Sign
End If
Next
Combine = Left(OutStr, Len(OutStr) - 5)
End Function
In any cell type =Combine(Range)
i.e.
=Combine(A1:A500)
use concat function if you can add an additional column in the excel like this:
=CONCAT(D3:E5)
Attached sample image with input, additional column, output and formula
I assume you want to merge the data in the 3 cells into a single cell with a space between the 3 data set.
If that is the case then you can do it simply by using the Concatenate function in excel.
In the above example, you have data in Cells A1, A2 & A3.
Cell C1 has the merged data. As you can see, we have used CONCATENATE Function.
The space has been defined in Double quotes. So if you need a Hyphen (-), you can put that in Double Quotes with space “ - ” and it will display the result with Sanjay - Singh - Question
Hope this helps.

Excel PivotTables with Dynamic field names

I need to complete a large number of pivottable formula using criteria/fieldnames that are above/to left of cells. The base, static formula is as follows:
=GETPIVOTDATA("BDGT",'Pipeline PVT'!$A$6,"FiscalQuarter","FY16-Q3","AreaName","Western Europe")
I want to grab the value field (BDGT in this example) from the formula heading, which will be BDGT. But when I replace "BDGT" with a cell reference (ie: A4), I get #REF.
Any ideas why this is not working?
=GETPIVOTDATA(A4 & "",'Pipeline PVT'!$A$6,"FiscalQuarter","FY16-Q3","AreaName","Western Europe")
The & "" after A4 is the important bit...

Excel and cell formatting to text

I have a cell with the contents of 41316. I have it formatted as 20130211.
I need another cell to reference that value, but in the cell have it showing as 20130211 not 41316 formatted.
This maybe an easy one, but for some reason it has me running in circles.
Thanks in advance for all responses.
Excel by default copies the format from a cell formatted as a date to a cell which references it. It sounds in your case that Excel hasn't done that for you, so you just need to format the new cell with your special format : paintbrush tool or Edit..Copy, Edit..Past Special..Formats or Format..Number..Custom and select your format, which will be at the bottom of a long list.
If a string is ok instead of a number, you can decompose that date in parts and concatenate:
Being A1 the cell containing the value:
= Year(A1) & "/" & Month(A1) & "/" & Day(A1)
The "&" symbol concatenates text. The slashes are optional if you want them separated by slashes.
if your cell referencing 20130211 is 'A1' put =TEXT(A1,"####") in your calculation cell. If you do it this way then it will still read as a number and not a string

Resources