Vim tabular alignment first column different - vim

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 }

Related

Receiving Application defined error for this folmula

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" & ")"

Unwanted double quote in first line of file being written out

I am writing a to a txt file and the first character in the first line, when I view the file in notepad is a double quote. If I examine the variables that get written out when the code is running, the double quote is not there. Any ideas what might be wrong? Here is my code snippet:
mydata1 = "!TRNS" & vbTab & vbTab & "TRNSID" & vbTab & "TRNSTYPE" & vbTab &
"DATE" & vbTab & "ACCNT" & vbTab & "CLASS" & vbTab & "AMOUNT" & vbTab &
"DOCNUM" & vbTab & "MEMO" & vbCrLf
mydata1 = mydata1 & "!SPL" & vbTab & "SPLID" & vbTab & "TRNSTYPE" & vbTab &
"DATE" & vbTab & "ACCNT" & vbTab & "CLASS" & vbTab & "AMOUNT" & vbTab &
"DOCNUM" & vbTab & "MEMO" & vbCrLf
mydata1 = mydata1 & "!ENDTRNS" & vbTab & vbTab & vbTab & vbTab & vbTab &
vbTab & vbTab & vbTab & vbCrLf
mydata1 = mydata1 & "TRNS" & vbTab & "GENERAL JOURNAL" & vbTab & myDate &
vbTab & "ACCOUNTS REC-CORP OFFICE" & vbTab & "CORPORATE OFFICE" & vbTab &
mytot & vbTab & myDate & vbTab & vbCrLf
mydata1 = mydata1 & mydata2
file = "d:\junk\todd\tester.txt"
Open myfile For Output As #1
Write #1, mydata1
Close #1
You can use below syntax and see if it works for you:
Print #1, mydata1
BTW, the variable myfile and file do not match in your code.

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.

Qutation Marks within VBA for IF statement

I am trying to copy an IF formula in a range, but my issue, much like others, comes from the double quotes. I currently have CHR(34) to indicate I want the double quote, but my VBA error is Expected end of line.
How I need it to appear as a formula:
=IF(D2=team,"",IF(D2=on," - Type1",IF(OR(D2=lr,D2=sn),"*"," - Type3")))
team, on, lr, sign are variables that refer to strings.
Range()= "=IF(D2=" & team & ", "&Chr(34)&Chr(34)&",IF(D2=" & on & ","&Chr(34)&" - Type1"&Chr(34)&",IF(OR(D2=" &lr& ",D2=" &sn& "),"&Chr(34)&"*"&Chr(34)&","&Chr(34)&" - Type3"& Chr(34)&")))"
It presents the error in the second instance of D2 in the OR statement
I believe the following should work as you expect it to, I simply changed the variable name from on to oni as I don't think you can have a variable named on also I separated the &'s with spaces:
ActiveCell.Formula = "=IF(D2=" & team & ", " & Chr(34) & Chr(34) & ",IF(D2="" & oni & ""," & Chr(34) & " - Type1" & Chr(34) & ",IF(OR(D2=" & lr & ",D2=" & sn & ")," & Chr(34) & "*" & Chr(34) & "," & Chr(34) & " - Type3" & Chr(34) & ")))"

Excel Hyperlink does not work

I have been batling this suposedly simple problem for 2 hours now and I just cant figure it out. I am trying to make a link and no matter how many " marks I try it always ends up in error or the link says & Poracun(Z).Ime & Can anyone find me a way that I can change the link name ?
Here is my code:
Cells(i, "B").Formula = "=HYPERLINK(""[" & ActiveWorkbook.Path & "\" & "DN_Pokalkulacija.xlsx" & "]" & "'" & "Sheet1" & "'" & "!E" & Poracun(Z).Vrstica & ""","" & Poracun(Z).Ime & "")"
Two issues:
Your " delimiting is not quite right
Formula expects ' around the file name, not the sheet. Like '[FileName]SheetName'!
Try
Cells(5, "B").Formula = "=HYPERLINK('[" & ActiveWorkbook.Path & "\" & "DN_Pokalkulacija.xlsx" & "]" & "Sheet1" & "'" & "!E" & Poracun(Z).Vrstica & ",""" & Poracun(Z).Ime & """)"
I have figured it out , it was quotation problem, i forgot all about it and now i have read up on it inside quotation string you need to make double quotation to use as single in final string. Here is a working link :
g = "=HYPERLINK(""[" & ActiveWorkbook.Path & "\" & "DN_Pokalkulacija.xlsx" & "]" & "'" & "Sheet1" & "'" & "!E" & Poracun(Z).Vrstica & """,""" & Poracun(Z).Ime & """)"
It was all in quotation (") marks :)

Resources