Excel macro - adding a word to a currency field - layout

I've successfully copied a currency value to a field. Now I need to add a word, but this always makes me lose my currency format. Is there a way to solve this?
Example
Range("A2").Value = Range("A1") & "/link"
"Output"
A1 = € 2.800,00
A2 = 2800/link
"Wanted output"
A2 = € 2.800,00/link
I know I can record a macro and copy that, but that's only applicable for that certain case. The number is variable.
Thank you for your help.

Range("A2").Value = Range("A1").Text & "/link"

Related

How can I apply dynamic number formatting?

I've programmed an Excel document for my cryptocurrency portfolio. I add new currencies in a table, to which I pull data via an API to get the prices. I format the result like this: #.##0,00000000 [$ETH] (for Ethereum).
What I would like to achieve is, that when I input currency in column A, the value in column B is formatted to this currency.
Example: http://prntscr.com/p3sof8
So if I input XRP in A5, the value in B5 would read 0,00000000 XRP.
There's no fixed number of currencies I'd use, since I may add new every day.
Basic version of the above logic would be:
Input currency from column A into formatting argument like: #.##0,00000000 [$], except for BTC where the format would be: ฿0,00000000
.
Place this in your Sheet e.g "Sheet1"
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count = 1 Then
If .Column = 1 Then
If .Value <> "BTC" Then
.Offset(, 1).NumberFormat = "0.00000000" & """ " & .Value & """"
Else
.Offset(, 1).NumberFormat = """" & ChrW(&HE3F) & """" & "0.00000000"
End If
End If
End If
End With
End Sub
No need to use VBA. You can do this with conditional formatting.
To do the specific example:
Go to cell B5
Click Conditional Formatting > New Rule...
Select Use a formula to determine which cells to format
As the formula, put =$A$5="XRP"
Click Format and on the Number tab, set it to custom such as #.##0,00000000 [$XRP]
I will leave it up to you to generalize this

Formatting a line in a comment using VBA

I'm struggling to find a way to format a line that in a comment that is required to be a currency value.
I've set the variable as currency, but it reverts back to basic when used in a comment.
Dim wage As Currency
wage = Range("b14")
Range("C14") = wage
Range("D14").AddComment
Range("D14").Comment.Visible = False
Range("D14").Comment.Text Text:=
Application.UserName & Chr(10) & wage & Chr(10) & "Joe Bloggs"
When i hover the wage variable in break mode is showing the value in b14 as plain, however i require it to appear as currency (£#.##)
The following syntax appears when i start writing
Text([Text], [Start], [Overwrite]) as string
I'm not sure, but could the overwrite section be the key???
Thanks in advance
If cell B14 has already been formatted to the proper currency format, then replace:
Dim wage As Currency
wage = Range("b14")
with:
Dim wage as String
wage = Range("B14").Text

Write formula in VBA Excel

I have troubles with writing formula in Excel VBA.
Sub Macro()
valueA1 = Range("A1").Value
Range("C1").Formula = "=RC[-1]*" & valueA1
End Sub
At the end I want formula in cell C1 to be written as =B1*0,5, if value in B1 is 0,5.
Thaks for the help!
Excel doesn't like foreign languages. You will need to use FormulaR1C1Local:
Range("C1").FormulaR1C1Local = "=RC[-1]+" & valueA1
or maybe
Range("C1").FormulaR1C1Local = "=RC[-1]*" & valueA1
if you are trying to multiply B1*A1. (Your question says multiply, your code says add.)
That should cause it to accept "0,5" as a valid number.

How would I extract the formatted text from a cell in VBA?

Lets say A1 is a date formatted to "YYMMDD" and I enter 7/7/2014 in the cell.
The cells string changes to "140707" but the function bar still shows up as "7/7/2014"
When I try to write this code:
Dim dateCell As String
dateCell = Cells(1, "A")
dateCell will equal to "7/7/2014" and not "140707"
I want the cell to be formatted that way so that when anyone puts in a date, it'll automatically change it to yymmdd. Now how would I get the text dateCell to equal 140707 and not 7/7/2014?
I would greatly appreciate it!!
Thanks
You can see the three different ways to get at the value in a cell here. Put a date in A1, and format it as you format it.
Public Sub test()
Dim r As Range
Set r = Range("a1")
MsgBox ("Value:[" & r.Value & "] Value2:[" & r.Value2 & "] Text:[" & r.Text & "]")
End Sub
In your case you want the Text.
In VBA, you can declare a variable as type Date instead of String which will solve that part of the problem.
In Excel, you need to specify a custom number format to "yyMMdd". Excel will understand that this cell is a date from the value that is in it and extract the proper year, month and day and display it as you specified.

Search and return text from column in Excel

I have an Excel worksheet and am trying to figure out the formula for the following:
With my formula, I want to search all 700 rows of Column A for cells that contain aa_product11.12
Column A's value may or may not contain those values (some will, some will not). And, this is only the partial value. All of the cells have more data, i.e.
Column A
Sept01_aa_product11.12;
Oct01_aa_product11.12;
and so forth.
I need the full values of those cells that match, to show up in B1. So, the formula in B1 will search all of column A for aa_product11.12 and then B1 will look like:
Cell B1
Sept01_aa_product11.12, Oct01_aa_product11.12, Jan02_aa_product11.12,
Aug08_aa_product11.12
Thank you in advance for your help!
My answer will not immediately give you the concatenated results, but they are the step(s) before this:
Without formula:
Insert a filter and filter on Text with the criteria 'Contains aa_product11.12'.
Copy the column after the filter and paste the results in a fresh sheet.
You can then remove the filter and transfer the results back to the original sheet.
With a formula:
In B1, put the formula:
=IFERROR(INDEX($A$1:$A$700,SMALL(IF(ISNUMBER(FIND("aa_product11.12",$A$1:$A$700)),ROW($A$1:$A$700),9.9E+208),ROW())),"")
But this is an array formula which will require using Ctrl+Shift+ to work properly. After this, fill down the formula until there are no more results returned to proceed to the last step.
After doing either of these, you can run a CONCATENATE on the cells:
=CONCATENATE(B1,", ",B2,", ", ... )
Okay, You need to open your Visual Basic Editor and create a module. Place the following code in your module:
Function Get_Data()
Dim Strg As String
Dim Boo As Boolean
Boo = False
Dim i
i = 1
For i = i To 65000
Strg = Cells(i, 1).Value
If InStr(1, Strg, "aa_product11.12") Then
If Boo = True Then
Get_Data = Get_Data & Cells(i, 1).Value & ", "
Else
Get_Data = Cells(i, 1).Value & ", "
Boo = True
End If
End If
Next i
End Function
Save file as a Macro-Enabled workbook. Then go to cell B1 and type in: =Get_Data()
Press enter and the function should work. Let me know if you have any questions.

Resources