All of my formulas are converting without any issues it's just these following two formulas are giving me an error when I try to convert them to R1C1. Can someone please advise why is this happening ?
"=IF(Control!$B$116=1,"",IF(A24="","",IF('Sub Lot Input'!$L$25="","",IF(OR('Calcs - Conversion'!DJ9="",'Calcs - Conversion'!DJ9="-"),"-",IF(OR(Other_Analysis_Input_Field=4,Other_Analysis_Input_Field=5),MROUND('Calcs - Conversion'!DJ9,'Calcs - Conversion'!$AC$66),'Calcs - Conversion'!DJ9)))))"
"=IF(OR('Control'!$B$235=TRUE,'Control'!$B$236=TRUE),IF('Additional Analysis Input'!$C$14="","Degree C.",'Additional Analysis Input'!$C$14),"")"
I am converting the formula to R1C1 using the following line of code:
Formula = Application.ConvertFormula( _
Formula:=wk_sht.Range(cell).Formula, _
fromReferenceStyle:=xlA1, _
toReferenceStyle:=xlR1C1)
I am getting type mismatch error.
Related
I am trying to convert the following IF statement into text that will be filled into a cell through VBA:
=IF(XLOOKUP(N7,'EDL Filter'!R2:R660,'EDL Filter'!AA2:AA660)="YES","Port Specific",XLOOKUP(N7,'EDL Filter'!R2:R660,'EDL Filter'!AB2:AB660) )
I've tried splitting it up as I have with other Xlookup statements below:
ActiveCell = "=IF(XLookUp(N" & SafetyRow2 & ",'EDL Filter'!R2:R660,'EDL Filter'!AA2:AA660)=""Yes"",""Port Specific"", Xlookup(N" & SafetyRow2 & ",'EDL Filter'!AB2:AB660))"
However, I keep getting Run-time Error '1004': Application-defined or object-defined error.
The variables have been defined and used earlier in my code without issue, but I am still new to VBA so I might be missing something obvious.
We have an excel, which contains some VBA code. For a table we write some VBA code to set up some preparation like these:
Worksheets("Activity Features").range("ActivityFeaturesTable[ProtonProject]").Formula = "=VLOOKUP([Proton],Table_PT2_Projects,2,FALSE)"
Worksheets("Activity Features").range("ActivityFeaturesTable[SUM]").Formula = "=SUM(ActivityFeaturesTable[#[C0001]:[C0500]])*#IF([#Multiplier]="""",1,[Multiplier])"
With Worksheets("Activity Features").range("ActivityFeaturesTable[StartDate]")
.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(INDIRECT(""RC[-1]"",0) = ""From StartDate to EndDate"", FALSE, TRUE)"
End With
This *.FormatConditions.Add Type:=xlExpression .. * line drops Invalid procedure call or argument error, however lines before this executes without any error.
The error occurs only on one client laptop, we cannot reproduce, several other users never experienced this error before. We checked the client computer settings, the Regional settings "List separator" was set to ";" instead of "," - but changing back to "," does not helped at all. And VBA code lines before this one also contains "," as separator in the formula.
We wonder why this error happens on the client side on this line?! Any idea? Is there any problem with the INDIRECT or RC in the formula?
Thanks in advance!
I have a vba code to fill dynamically conditionnal formatting. The problem is that my code works fine on english version of Excel, but if I send to someone with the french excel version, it's giving them an error.
I realized that the problem is that I put in my vba code a comma ',' in english version, but in french version it excpects a ";" separator to work.
How can I solve this so that my code works on any excel version ? I can't create an excel for each user, based on his local version.
To make things clear so that you may help :
here is the part of my code that is causing me the problem
sFormula is a string contaning :
sFormula=AND(OR($AP14="",$AR14=""),NOT($C14=""))
Range(sMyRange).FormatConditions.Add Type:=xlExpression, Formula1:=sFormula
In enlglish version of Excel All works fine
In french version I have to replace in my VBA code the ',' in sFormula by ';' to makes it work, otherwise I get a runtime error when the Macro code is executed
If I replace in my code the previous sFormula, by the following one (just changing the , by ;) it works fine on french version
sFormula=AND(OR($AP14="";$AR14="");NOT($C14=""))
Thanks in advance for your help.
I think you can write code by judging the language when installing Excel.
Dim sFormula As String
If Application.LanguageSettings.LanguageID(msoLanguageIDInstall) = msoLanguageIDEnglishAUS Then
sFormula = "=AND(OR($AP14="""",$AR14=""""),NOT($C14=""""))"
ElseIf Application.LanguageSettings.LanguageID(msoLanguageIDInstall) = msoLanguageIDFrench Then
sFormula = "=AND(OR($AP14="""",$AR14="""");NOT($C14=""""))"
End If
Range(sMyRange).FormatConditions.Add Type:=xlExpression, Formula1:=sFormula
Based on the comments of #Scott Craner , I solved my problem using the following functionThanks Again to Scott Craner and to #Dy.Lee for their help.
Here is my function so that it may help someone else :
Public Function GetLocalFormula(sformula As String, Optional sCell As String = "A1") As String
'This function will Convert and English formula to localized formula
'SCell is the temporary cell that we will use to convert the Formula, by default it's A1
Dim temporary As String
Dim result As String
With Range(sCell)
temporary = .formula
.formula = sformula
result = .FormulaLocal
.formula = temporary
GetLocalFormula = result
End With 'With Range(sCell)
End Function
I want to execute an advanced filter with vba. The problematic step is that the name of the source table (for the advanced filter) is written in a cell and it seems I can't find a way to pass it to range().
Here is the idea:
The F5 cell contain "DatePlace" and it is the name of the table that should be used in the advanced filter. By recording a macro I saw that we could use structured references in VBA but when I try to take the reference from the value of F5, the advanced filter doesn't execute anymore.
I receive this error message box (translated from french) :
Execution error '1004':
Error defined by the application or by the object
Here is one of my attempts :
Worksheets("Planning")
.Range(Worksheets("Macro").Range("$F$5").Text & "[[#Headers],[#Data]]")
.AdvancedFilter Action _:=xlFilterCopy,
CriteriaRange:=Worksheets("Planning").Range("E7:F8"),
CopyToRange:=Worksheets("Planning").Range( _"E11:F11"), Unique:=False
I tried with .Value instead of .Text. I tried to pass it with a string variable too. I also tried to write the full reference in the F5 cell. And when I tried to get a range variable I just moved the issue to that variable initiation.
Any help is welcomed.
Edit 1 :
This way of doing it works but I have to hard code the structured reference and that's exactly what I want to avoid.
Worksheets("Planning")
.Range("DateLieu[[#Headers],[#Data]]")
.AdvancedFilter Action _:=xlFilterCopy,
CriteriaRange:=Range("A6:B7"),
CopyToRange:=Range( _"A10:B10"), Unique:=False
Edit 2 :
It should have worked without issue. Here is how the code looks now.
' Variables
Dim rngPlanning As String
' Initiations
rngPlanning = ThisWorkbook.Worksheets("Macro").Range("$F$5").Text & "[[#Headers],[#Data]]"
' Actions
Application.CutCopyMode = False
Debug.Print (rngPlanning)
Worksheets("Planning").Range(rngPlanning).AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Worksheets("Macro").Range("$E$7:$F$8"), _
CopyToRange:=Worksheets("Macro").Range("$E$11:$F$11"), _
Unique:=False
I'm trying to use the following formula, but am getting the error application defined or object defined error. I have a feeling it's due to the line break, but it looks good to me.
ActiveCell.FormulaR1C1 = _
"=IF(AND(R[1]C[-13]=RC[-13],R[1]C[-15]=RC[-15]),IF(AND(R[1]C[-8]=RC[-8],R[1]C[-3]<>RC[-3]),IF(AND(R[2]C[-8]=R[1]C[-8],R[2]C[-3]<>R[1]C[-3]),IF(AND(R[3]C[-8]=R[2]C[-8],R[3]C[-3]<>R[2]C[-3]),IF(AND(R[4]C[-13]=R[3]C[-13],R[4]C[-15]=R[3]C[-15]),"""",RC[-3]),IF(AND(R[3]C[-13]=R[2]C[-13],R[3]C[-15]=R[2]C[-15]),"""",RC[-3]))," & _
"IF(AND(R[2]C[-13]=R[1]C[-13],R[2]C[-15]=R[1]C[-15],"""",RC[-3])),""""),IF(RC[-3]="""","""",RC[-3]))"