theflyingdutchdog
New Member
- Joined
- Jun 2, 2017
- Messages
- 39
So I have to take symbols for electronic components (like CK and CK#), and I have to come up with a program that formats them in Latex.
I typed in the original symbols to be formatted in separate columns in Excel. Then I created a column next to each column of the original symbols. What I am being told to do is come up with a program (VBA or otherwise) that will automatically format the original column of symbols to Latex and put those new Latex symbols in a column adjacent to the original.
So if I have CK# in Column A, I need a program that will spit out CK\# in Column B.
My two main problems are superscripts/subscripts and overline characters. To put superscipt/subscript characters in, I thought I could use Word's Find and Replace after running my code. (I still haven't figured out overline.) But my code with the Replace function changes the format of the subscripts/superscripts to regular font.
How do I keep my code with the Replace function from changing the format of subscripts/superscripts?
Here's my code:
Sub Latexualize()
Dim rng As Range
Dim cell As Range
Dim txt As String
Dim wsOut As Worksheet
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeConstants)
Set wsOut = ActiveWorkbook.Sheets.Add(Type:=xlWorksheet)
For Each cell In rng
txt = cell.Value
' Add Replace() steps below, as needed
txt = Replace(txt, "", "\backslash")
txt = Replace(txt, "_", "\_")
txt = Replace(txt, "#", "\#")
txt = Replace(txt, ChrW(916), "\Delta")
txt = Replace(txt, ChrW(&H221E), "\infty")
' Output to new worksheet
wsOut.Cells(cell.Row, cell.Column).Value = txt
Next
End Sub
I typed in the original symbols to be formatted in separate columns in Excel. Then I created a column next to each column of the original symbols. What I am being told to do is come up with a program (VBA or otherwise) that will automatically format the original column of symbols to Latex and put those new Latex symbols in a column adjacent to the original.
So if I have CK# in Column A, I need a program that will spit out CK\# in Column B.
My two main problems are superscripts/subscripts and overline characters. To put superscipt/subscript characters in, I thought I could use Word's Find and Replace after running my code. (I still haven't figured out overline.) But my code with the Replace function changes the format of the subscripts/superscripts to regular font.
How do I keep my code with the Replace function from changing the format of subscripts/superscripts?
Here's my code:
Sub Latexualize()
Dim rng As Range
Dim cell As Range
Dim txt As String
Dim wsOut As Worksheet
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeConstants)
Set wsOut = ActiveWorkbook.Sheets.Add(Type:=xlWorksheet)
For Each cell In rng
txt = cell.Value
' Add Replace() steps below, as needed
txt = Replace(txt, "", "\backslash")
txt = Replace(txt, "_", "\_")
txt = Replace(txt, "#", "\#")
txt = Replace(txt, ChrW(916), "\Delta")
txt = Replace(txt, ChrW(&H221E), "\infty")
' Output to new worksheet
wsOut.Cells(cell.Row, cell.Column).Value = txt
Next
End Sub