I have data in column A, C, E and G. I want column I to hold all of the data from these separated by semicolons, I have searched the web but all I find is how to replace line breaks with semicolons and that doesn't do it. Below are the 3 pieces of code I have attempted to work into it
Range("I" & i).Value = "=A" & i & Chr(59) & "&" & "C" & i & "&" & "E" & i & "&" & "G" & i
Range("I" & i).Value = "=A" & i & "&C" & i & "&E" & i & "&G" & i
Range("I" & i).Value = Range("A" & i).Value + ; + Range("C" & i).Value + ; + Range("E" & i).Value + ; + Range("G" & i).Value
The second line comes closest to what I want but when I add & ";" into it I get errors.
Any ideas thoroughly appreciated
SOLVED : This was solved by an answer below, I had managed my own fix which I will detail but the accepted answer is a cleaner, more efficient way
mystring = "=A" & i & "&" & Chr(34) & ";" & Chr(34) & "& C" & i & "&" & Chr(34) & ";" & Chr(34) & "& E" & i & "&" & Chr(34) & ";" & Chr(34) & "& G" & i
Range("I" & i).Value = mystring
You should use "&"";""".
In detail, you should use something like
"=A" & i & "&"";""" & "&C" & i
which result in
=A1&";"&C1
suppose i = 1.
=CONCATENATE(A1, ";", C1, ";", E1, ";", G1)
Using VBA
Range("A2").FORMULA = REPLACE("=CONCATENATE(A1, ';', C1, ';', E1, ';', G1)", "'", CHR(34))
Related
I asked for advice everywhere but with no help so far!
= Evaluate("INDEX(TEMPDB!E" & lrCHIIMPORT2 + 1 & ":E" & lr3CHIMPORT2 & ",
MATCH(STATIONS!B" & RARTSTAT3 & "& STATIONS!" & matchARTIST & "1, TEMPDB!C" &
lrCHIIMPORT2 + 1 & ":C" & lr3CHIMPORT2 & " & TEMPDB!A" & lrCHIIMPORT2 + 1 &
":A" & lr3CHIMPORT2 & "))")
I get
Error 2042
Both criteria is STRING, output is INTEGER or STRING!
Sheets("STATIONS").Evaluate("INDEX(TEMPDB!E" & lrCHIIMPORT2 + 1 & ":E" &
lr3CHIMPORT2 & ", MATCH(STATIONS!B" & RARTSTAT3 & "& STATIONS!" & matchARTIST
& "1, TEMPDB!C" & lrCHIIMPORT2 + 1 & ":C" & lr3CHIMPORT2 & " & TEMPDB!A" &
lrCHIIMPORT2 + 1 & ":A" & lr3CHIMPORT2 & ",0))")
i can't believe... Just FALSE on the end...!
I'm trying to insert formulas into cells using this following code:
ActiveCell.Formula = "=ISERROR(IF(O" & ActiveCell.Row & "=M; _
LEFT(O" & ActiveCell.Row & ";LEN(O" & ActiveCell.Row & ")-1)*1000000; _
LEFT(O" & ActiveCell.Row & ";LEN(O" & ActiveCell.Row & ")-1)*1000000000);" & vide & ")"
(vide is a string variable) but it keeps returning Application defined or Object defined error.
Thanks !
Change ; to ,
Change " & vide & " to """ & vide & """
Change M to ""M""
Change ISERROR to IFERROR
ActiveCell.Formula = "=IFERROR(IF(O" & ActiveCell.Row & "=""M"",LEFT(O" & ActiveCell.Row & ",LEN(O" & ActiveCell.Row & ")-1)*1000000,LEFT(O" & ActiveCell.Row & ",LEN(O" & ActiveCell.Row & ")-1)*1000000000),""" & vide & """)"
It's because of your local settings, you use ; unstead of ,.
If you must use ;, then try replacing:
ActiveCell.Formula
with:
ActiveCell.FormulaLocal
Also, I like to use Chr(34) to get the ".
So at the end change your formula to:
...1000000000);" & Chr(34) & vide & Chr(34) & ")"
Could someone quickly tell me what's wrong with this syntax?
Sheets("Sheet1").Range("D" & i, "B" & i, "I" & i, "E" & i, "N" & i, "P" & i).Copy
This one is correct:
Sheets("Sheet1").Range("D" & i & ",B" & i & ",I" & i & ",E" & i & ",N" & i & ",P" & i).Copy
comma , should be inserted as string. I.e. you're trying to use (which is wrong):
Sheets("Sheet1").Range("D1","B1","I1","E1","N1","P1").Copy
but you should use:
Sheets("Sheet1").Range("D1,B1,I1,E1,N1,P1").Copy
I need to write in the cells from Cells(1,1) to Cells(501,1) the formula
=FDSC("-",$C$3,"FG_PRICE(D1)") for line 1
=FDSC("-",$C$3,"FG_PRICE(D2)") for line 2
=FDSC("-",$C$3,"FG_PRICE(D3)") for line 3
Now my vba code is the following one :
Range(Cells(1, 1), Cells(1 + 500, 1)).FormulaR1C1 = "=FDSC(""" & "-" & """,R1C3,""" & " FG_PRICE(RC[3]) " & """)"
I've tested everypart of the code to determine that the last part (FG_PRICE...) is the one that is not working!
The formule that is written in Excel is :
=FDSC("-",$C$1,"FG_PRICE(RC[3])")
How can i do to have D1,D2,etc... and not RC[3]??? I've tried a few things but i can't find it!
Thank you very much for your time and your help!
Use chr(34) to represent quotation marks when you are already working inside quotation marks. For example, change your forumula above to the following:
Range(Cells(1, 1), Cells(1 + 500, 1)).FormulaR1C1 = "=FDSC(" & chr(34) & "-" & chr(34) & ",$C$1," & chr(34) & "FG_PRICE(D1)" & chr(34) & ")"
To put it in a loop, just do the following:
Sub writeFormulas()
Dim i as Integer
For i = 0 to 2
Range(Cells(1, 1), Cells(1 + 500, 1)).FormulaR1C1 = "=FDSC(" & chr(34) & "-" & chr(34) & ",$C$1," & chr(34) & "FG_PRICE(D" & i+1 & ")" & chr(34) & ")"
next i
End Sub
I want to make a formula with a & inside it but VBA thinks its a concatenate symbol
""&"" does not work, are there any other tricks?
My formula:
Sheets("Elasticity").Cells(iRow, 38).Formula = "=SUMIFS(" & "All_Models!$W$2:$W$" & nrow & ",All_Models!$G$2:$G$" _ & nrow & ",Elasticity!L" & iRow & ",All_Models!$AL$2:$AL$" & nrow & ",Elasticity!AK" & iRow & _ ",All_Models!$B$2:$B$" & nrow & "," & "" <= "" & "&" & "ElasticityA" & iRow & ")"
I want to transform:
"" <= "" & "&" & "Elasticity!A" & iRow & ")"
into:
"<="&Elasticity!A2)
How about just this:
dim s as string
s = "my_complicated_formula" & "&" & "and_another_formula"
...All_Models!$B$2:$B$" & nrow & ",""<=""&" & "Elasticity!A" & iRow & ")"
s="foo" & Chr(38) & "bar"
Where chr(38) = &