Receiving Application defined error for this folmula - excel

I am getting application-defined error 1004 for the formula where I am trying to find the cells with only public email ids such as gmail yahoo etc. I replaced # with # previously.
Dim n As String
n = vbNullString
ActiveCell.Formula = "=IF(LEN(G2)-LEN(SUBSTITUTE(G2," & "#" & "," & n & "))=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(G2," & "#gmail.com" & "," & "^" & ")," & "#yahoo.com" & "," & "^" & ")," & "#yahoo.co.in" & "," & "^" & ")," & "#rediffmail.com" & "," & "^" & ")," & "#hotmail.com" & "," & "^" & "))-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(G2," & "#gmail.com" & "," & "^" & ")," & "#yahoo.com" & "," & "^" & ")," & "#yahoo.co.in" & "," & "^" & ")," & "#rediffmail.com" & "," & "^" & ")," & "#hotmail.com" & "," & "^" & ")," & "^" & "," & "))," & "All Public recipients" & "," & "OK" & ")"

Related

Formula combination of SUMIFS, Tables & Variables in Excel VBA

I am trying to loop through the Headers of the Table and then populate the formula as mentioned below:
Dim headerRng As Range
For Each headerRng In IndMetricsSht.ListObjects(TableName2).Range.Rows(1).Cells
Debug.Print headerRng
If headerRng.Value <> "Function" And headerRng.Value <> "Team Members" And headerRng.Value <> "Accuracy %" Then
IndMetricsSht.ListObjects(TableName2).ListColumns(headerRng.Value).DataBodyRange.Select
Selection.FormulaR1C1 = "=SUMIFS(INDIRECT(" & Chr(34) & TableName & Chr(34) & " & ""["" & [#[Team Members]] & CHAR(10) & ""Volumes"" & ""]"")," & Chr(34) & TableName & Chr(34) & " & ""["" & [#[Sub-Function]] & ""]"",LEFT(" & Chr(34) & headerRng.Value & Chr(34) & ",FIND(""_""," & Chr(34) & headerRng.Value & Chr(34) & ")-1))" 'I'm facing error (application object error)
End If
Next
Actual formula in Excel sheet looks like:
=SUMIFS(INDIRECT("IM_012022" & "[" & [#[Team Members]] & CHAR(10) & "Volumes" & "]"),IM_012022[Sub-Function],LEFT(Consolidated_012022[[#Headers],[Corporate Treasury_Volumes]],FIND("_",Consolidated_012022[[#Headers],[Corporate Treasury_Volumes]])-1))
I'm trying to replicate the same formula for each header using the loops concept, but somwhere in that formula, I'm missing.
Dim HeaderRng As Range
For Each HeaderRng In IndMetricsSht.ListObjects(TableName2).Range.Rows(1).Cells
Debug.Print HeaderRng
If HeaderRng.Value <> "Function" And HeaderRng.Value <> "Team Members" And HeaderRng.Value <> "Volumes" And Not (HeaderRng.Value Like "*Errors") And HeaderRng.Value <> "Accuracy %" Then
IndMetricsSht.ListObjects(TableName2).ListColumns(HeaderRng.Value).DataBodyRange.Select
Selection.FormulaR1C1 = "=SUMIFS(INDIRECT(" & Chr(34) & TableName & Chr(34) & " & ""["" & [#[Team Members]] & CHAR(10) & ""Volumes"" & ""]""),INDIRECT(" & Chr(34) & TableName & Chr(34) & " & ""[Sub-Function]""),LEFT(" & Chr(34) & HeaderRng.Value & Chr(34) & "," & InStr(1, HeaderRng.Value, "_") - 1 & "))"
End If
Next

Inserting formula as string into a cell

It seems to be a problem with some characters in it
My original formula in the worksheet (working):
ThisWorkbook.Worksheets("Zazmluvnenia").Cells("3", "AM").Value = "=Výkony!M4 & ", " & TEXT(Výkony!J4;"d.m.yyyy") & ", " & TEXT(Výkony!K4;"hh:mm")"
Putting this into VBA doesn't work because of the quotes. I tried to solve the problem this way: How do I put double quotes in a string in vba?
I changed my code according to the answers on the question above:
"=Výkony!M3 & " & Chr(34) & ", " & Chr(34) & " & TEXT(Výkony!J3;" & Chr(34) & "d.m.yyyy" & Chr(34) & ") & " & Chr(34) & ", " & Chr(34) & " & TEXT(Výkony!K3;" & Chr(34) & "hh:mm" & Chr(34) & ")"
And error '1004' occurred.
Double Quotes vs CHR(34)
Your CHR solution was almost fine, but you didn't know that VBA doesn't recognize the semi-colon (;) as a separator like Excel does. You always have to replace every semi-colon (used as a separator) with a comma in VBA.
Similarly VBA uses the dot (.) as the decimal separator.
The Code
Option Explicit
Sub SEMI()
Dim strF As String
' Double double-quotes ("") in several rows.
strF = "=Výkony!M4&"", """ _
& "&TEXT(Výkony!J4,""d.m.yyyy"")&"", """ _
& "&TEXT(Výkony!K4,""hh:mm"")"
' CHR(34) in several rows.
strF = "=Výkony!M4&" & Chr(34) & ", " & Chr(34) _
& "&TEXT(Výkony!J4," & Chr(34) & "d.m.yyyy" & Chr(34) & ")&" _
& Chr(34) & ", " & Chr(34) _
& "&TEXT(Výkony!K4," & Chr(34) & "hh:mm" & Chr(34) & ")"
' Double double-quotes ("") in one row.
strF = "=Výkony!M4&"", ""&TEXT(Výkony!J4,""d.m.yyyy"")&"", ""&TEXT(Výkony!K4,""hh:mm"")"
' CHR(34) in one row.
strF = "=Výkony!M4&" & Chr(34) & ", " & Chr(34) & "&TEXT(Výkony!J4," & Chr(34) & "d.m.yyyy" & Chr(34) & ")&" & Chr(34) & ", " & Chr(34) & "&TEXT(Výkony!K4," & Chr(34) & "hh:mm" & Chr(34) & ")"
ThisWorkbook.Worksheets("Zazmluvnenia").Cells("3", "AM").Value = strF
End Sub

VLOOKUP from another spreadsheet using VBA

I have a master spreadsheet that analyzes records from another spreadsheet with rows going all the way up to 1.4 million.
Below are the relevant pieces from the code:
Sub Whyamidoingthis()
Dim USISINLfp As String
Dim ISINL As String
Dim echeck As String
Dim wUSISIN As Workbook
Dim lastrow As Long
Dim Result As Worksheet
Dim i As Long
Set OutShVar = ThisWorkbook.Worksheets("in1")
ISINL = "CONSOLIDATED - Country_Of_Incorp_US_2019-03-01 (Consolidated).xlsx"
USISINLfp = "W:\Product Platforms\ISIN- CUSIP Country of Incorporation\March 2019\"
Workbooks.Open (USISINLfp & ISINL)
Set wUSISIN = Workbooks(ISINL)
With Result
lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
End With
'US Security 1
For i = 2 To lastrow
With Result
echeck = Trim(.Range("O" & i))
If echeck = "" Then
.Range("P" & i & ":Q" & i).Value = "N"
Else
.Range("P" & i).Value = "=ifna(vlookup(O" & i & "," & ISINL & "First Sheet'!$B:$C,2,false)," & Chr(34) & "N" & Chr(34) & ")"
.Range("Q" & i).Value = "=ifna(vlookup(O" & i & "," & ISINL & "Second Sheet'!$B:$C,2,false)," & Chr(34) & "N" & Chr(34) & ")"
'Debug.Print "=ifna(vlookup(O" & i & "," & ISINL & "Second Sheet'!$B:$C,2,0)," & Chr(34) & "N" & Chr(34) & ")"
End If
'US Security 2
echeck = Trim(.Range("S" & i))
If echeck = "" Then
.Range("T" & i & ":U" & i).Value = "N"
Else
.Range("T" & i).Value = "=ifna(vlookup(S" & i & "," & ISINL & "First Sheet'!$A:$C,3,false)," & Chr(34) & "N" & Chr(34) & ")"
.Range("U" & i).Value = "=ifna(vlookup(S" & i & "," & ISINL & "Second Sheet'!$A:$C,3,false)," & Chr(34) & "N" & Chr(34) & ")"
End If
End With
Next I
If Not wUSISIN Is Nothing Then wUSISIN.Close savechanges:=False
End Sub
The code is getting stuck at the following line:
.Range("T" & i).Value = "=ifna(vlookup(S" & i & "," & ISINL & "First Sheet'!$A:$C,3,false)," & Chr(34) & "N" & Chr(34) & ")"
Whenever a result is found and the error is application defined error.
Try this formula:
"=ifna(vlookup(O" & i & ",'[" & ISINL & "]First Sheet'!$B:$C,2,false)," & Chr(34) & "N" & Chr(34) & ")"
This places square brackets around the workbook name and single quotes around the workbook-worksheet combo. See this tutorial about using VLOOKUP from another workbook.

Formula/VBA - Application defined or object defined error

I'm trying to create a vba code to write a formula in determined cell on my sheet, but it doesn't work. What's wrong ? 'Cause, i really don't see what am i doing wrong in this code.
Range("BC" & ActiveCell.Row).Formula = "=IF($BB" & ActiveCell.Row & "=" & """" & "REVIEW" & """" & ";IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=" & """" & "OK" & """" & ";$A:$A));IF(TODAY()-$AY" & ActiveCell.Row & ">=3;" & """" & "DROP" & """" & ";" & """" & "REVIEW" & """" & ");" & """" & "REVIEW" & """" & ");" & """" & """" & ")"
Your computer's use of a ; as the regional list separator is fouling you up. VBA is very EN-US-centric so the Range.Formula and Range.FormulaR1C1 expect a comma (,) as the function's argument list separator.
Range("BC" & ActiveCell.Row).Formula = "=IF($BB" & ActiveCell.Row & "=" & """" & "REVIEW" & """" & ", IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=" & """" & "OK" & """" & ", $A:$A)), IF(TODAY()-$AY" & ActiveCell.Row & ">=3, " & """" & "DROP" & """" & ", " & """" & "REVIEW" & """" & "), " & """" & "REVIEW" & """" & "), " & """" & """" & ")"
Alternately, Range.FormulaLocal property or Range.FormulaR1C1Local property can be used with your own semi-colon as the list separator.
Range("BC" & ActiveCell.Row).FormulaLocal = "=IF($BB" & ActiveCell.Row & "=" & """" & "REVIEW" & """" & ";IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=" & """" & "OK" & """" & ";$A:$A));IF(TODAY()-$AY" & ActiveCell.Row & ">=3;" & """" & "DROP" & """" & ";" & """" & "REVIEW" & """" & ");" & """" & "REVIEW" & """" & ");" & """" & """" & ")"
Your doubling up double quotes within a quoted string is a bit verbose and xlR1C1 notation would save some steps. TEXT(,) is the same as "" in a formula; each produces the same zero-length string.
Range("BC" & ActiveCell.Row).Formula = "=IF($BB" & ActiveCell.Row & "=""REVIEW"", IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=""OK"", $A:$A)), IF(TODAY()-$AY" & ActiveCell.Row & ">=3, ""DROP"", ""REVIEW""), ""REVIEW""), TEXT(,))"
'.FormulaR1C1
Range("BC" & ActiveCell.Row).FormulaR1C1 = "=IF(RC54=""REVIEW"", IF(ROW(R:R)<MAX(IF(C54:C54=""OK"", C1:C1)), IF(TODAY()-RC51>=3, ""DROP"", ""REVIEW""), ""REVIEW""), TEXT(,))"
The xlA1 and xlR1C1 formula rewrites above each produce the following when ActiveCell is on the second row.
=IF($BB2="REVIEW", IF(ROW($BB2)<MAX(IF($BB:$BB="OK", $A:$A)), IF(TODAY()-$AY2>=3, "DROP", "REVIEW"), "REVIEW"), TEXT(,))
As I mentioned in comments above, that formula would seem to be an array formula. In that case, use the .Formula comma based rewrite but change the Range.Formula property to Range.FormulaArray.

Vim tabular alignment first column different

I’m trying to format tables in LaTeX nicely using the Tabular command, and frequently I’ll want to right-align the leftmost column, then left align everything else. Using :'<,'>Tabularize /&/r1c1l0 almost works, but only on the first column pair; the rest of the table is weirdly aligned almost as if Tabular is repeating that sequence.
How can I write a command that will align the table code without me having to type something like :'<,'>Tabularize /&/r1c1l0c1l0c1l0…?
EDIT: Example table code
\begin{longtable}{>{\bfseries}l >{\scshape}Fl -l -l -l -l -l -l -l -l -l -l}
\toprule
Case & & \SetRowStyle{\scshape} nil & 1sg & 2sg & 3sg & 1du;inc & 2du & 1pl;inc & 1pl;exc & 2pl & 3pl \\
\midrule\endhead
\multirow{4}{*}{Focal} & nat & -a & -ai & -uta & -ima & -iva & -etua & -isa & -ečé & -atá & -amia \\
& sgv & -ena & -enai & -enta & -enima & -eniva & -entua & -enisa & -enčé & -entá & -emia \\
& du & -eva & -evai & -evta & -evima & -eviva & -evtua & -evisa & -evčé & -evtá & -evmia \\
& pl & -esa & -esai & -esta & -esima & -esiva & -estua & -esisa & -esčé & -está & -esmia \\
\midrule
\multirow{4}{*}{Nominative} & nat & -am & -aim & -utam & -imam & -ium & -etum & -isam & -ečem & -atám & -amim \\
& sgv & -enam & -enaim & -entam & -enimam & -enium & -entum & -ensim & -enčem & -entám & -emim \\
& du & -evam & -evaim & -evtam & -evimam & -evium & -evtum & -evsim & -evčem & -evtám & -evmim \\
& pl & -esam & -esaim & -estam & -esimam & -esium & -estum & -essim & -esčem & -estám & -esmim \\
\midrule
\multirow{4}{*}{Absolutive} & nat & -aš & -aiš & -utaš & -imaš & -iuš & -etuš & -isaš & -ečeš & -atáš & -amiš \\
& sgv & -enaš & -enaiš & -entaš & -enimaš & -eniuš & -entuš & -ensiš & -enčeš & -entáš & -emiš \\
& du & -evaš & -evaiš & -evtaš & -evimaš & -eviuš & -evtuš & -evsiš & -evčeš & -evtáš & -evmiš \\
& pl & -esaš & -esaiš & -estaš & -esimaš & -esiuš & -estuš & -essiš & -esčeš & -estáš & -esmiš \\
\bottomrule
\caption{Consonant-final animate noun suffixes\label{tab:nst_animate_consonant_stem_suffixes}}
\end{longtable}
It compiles just fine but I’d like the source code to be formatted somewhat nicer.
You may find vim-easy-align useful.
Try
:'<,'>EasyAlign&mrl*
which is a shorthand notation for
:'<,'>EasyAlign & { 'mode_sequence': 'rl*' }
& tells the plugin to align text using predefined & rule for LaTeX tables
rl* means right, left, left, left, ...
You can adjust left and right margin around the delimiter as follows:
:'<,'>EasyAlign&mrl*l0r1
a shorthand notation for
:'<,'>EasyAlign & { 'mode_sequence': 'rl*', 'left_margin': 0, 'right_margin': 1 }

Resources