For i = 2 To 50
ws.Range("K" & i).FormulaLocal = "=if(countif($C$2:C" & i & ";C" & i & ")=1;row();"")"
Next i
ws.Range("K" & i).FormulaLocal = "=if(countif($C$2:C" & i & ";C" & i & ")=1;row();"")
I am getting error on this line. Where am I going wrong?
you need to double the quotation marks within the string (at the end):
ws.Range("K" & i).FormulaLocal = "=if(countif($C$2:C" & i & ";C" & i & ")=1;row();"""")"
Related
Below is my code that I am trying to append new text to an existing comment. However, when I execute, it is spitting an error - "Application defined/Object defined error". Could someone help?
For Each c In Range("G" & iCellIndex)
If StrComp(JSONObj2("fields")("worklog")("worklogs")(j + 1)("author")("displayName"), Range("G" & iCellIndex).Value) = 0 Then
Set cmt = ActiveCell.AddComment
cmt.Comment.Text iTimeStamp & "--" & JSONObj2("fields")("worklog")("worklogs")(j + 1)("timeSpent") , 1, False
Range("G" & iCellIndex).AddComment iTimeStamp & "--" & JSONObj2("fields")("worklog")("worklogs")(j + 1)("timeSpent") , 1, False
End If
iCellIndex = iCellIndex + 1
Next c
For those interested, this is how I fixed the issue:
If StrComp(JSONObj2("fields")("worklog")("worklogs")(j + 1)("author")("displayName"), Range("G" & iCellIndex).Value) = 0 Then
Range("G" & iCellIndex).NoteText Text:=Range("G" & iCellIndex).NoteText & Chr(10) & iTimeStamp & " -- " & JSONObj2("fields")("worklog")("worklogs")(j + 1)("timeSpent") & Chr(10)
End If
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) & ")"
I am trying to code this forumla in vba.
=MMULT(TRANSPOSE(F124:F370-L124),G124:G370-L125)/246
The code in vba I written looks like this:
Sheets("1.A").Cells(124, 14) = Application.WorksheetFunction.MMult(Application.WorksheetFunction.Transpose(Worksheets("1.A").Range("F" & matchStartRow & ":F" & matchEndRow) - Cells(124, 12)), Worksheets("1.A").Range("G" & matchStartRow & ":G" & matchEndRow) - Cells(125, 12)) / (matchEndRow - matchStartRow)
But it is giving me a type mismatch error. Not sure where it is coming from
It is much easier to use EVALUATE either directly as
Sheets("1.A").Cells(124, 14) = Evaluate("=MMULT(TRANSPOSE(F124:F370-L124),G124:G370-L125)/246")
or with your variables
Dim strEval As String
matchStartRow = 124
matchEndRow = 370
strEval = "=MMULT(TRANSPOSE(F" & matchStartRow & ":F" & matchEndRow & "-L124),G" & matchStartRow & ":G" & matchEndRow & "-L125)/(" & matchEndRow & " - " & matchStartRow & ")"
Sheets("1.A").Cells(124, 14) = Evaluate(strEval)
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))
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) = &