... in C/C++You could also process the CSV file with VBA, VBScript, or Powershell.
so I'll have to wait till tomorrow to view the macro and learn from it.If you don't understand the current 'Indent' sub, I can either answer specific questions or add more comments.
If I get cross-eyed going through the 60 pages, and accidentally skip a small H33, F33 combo, or maybe I just skip more than one header/footer. So I've labeled incorrectly. How to recover from this if I don't realize this until I get to the end of the doc?Currently, once you've added the headers and footers it won't allow you to do that, and while that could be changed, it would be easier [for me:) ] if you just manually edited it.
If you have a stack in your VBAI think what aikimark is talking about is simply that in VBA code if your are, say, referring to the active cell, you can refer to the cell 4 rows down and 2 columns to the right with ActiveCell.Offset(4, 2).
Scanning the table:...That is essentially what my code does now and has done in each version of the workbook, and it obviously does work but only if I can find the associated footer. If it were not for the fact that the headers and footers are nested, the approach as you described it would work. However when the headers and footers are like this
data1
20 first header
data2
33 second header
data3
55 footer associated with second header
data4
77 footer associated with first header
data5
Find first header; push 20 onto stack. Stack looks like:
20
Find second header; push 33 onto stack. Stack looks like:
33
20
Find a footer keyword - do these 4 steps:
1. record the row number of the footer.
55 = footer row #
2. Extract the row number at the top of the stack to get the row number of the associated header:
33 = header row #
3. Pop the stack; Stack now looks like:
20
4. Indent from (Header row # + 1) to (footer row # -1); that is
Indent from (33 + 1) to (55 -1)
Indent from (34) to (54)
Find a footer keyword - do these 4 steps:
1. record the row number of the footer.
77 = footer row #
2. Extract the row number at the top of the stack to get the row number of the associated header:
20 = header row #
3. Pop the stack; Stack now looks like:
<<empty>>
4. Indent from (Header row # + 1) to (footer row # -1); that is
Indent from (20 + 1) to (77 -1)
Indent from (21) to (76)
This approach should yield:data1
first header
data2
second header
data3
footer associated with second header
data4
footer associated with first header
data5
These numbers are kept internally in the macro...I hadn't thought of that, but I believe there's still a problem in that I don't think it would work with a structure like the one in the workbook which is this. I think it would fail at around line 10.
1st header
data
2nd header
data
3rd header
4th header
data
4th footer
data
3rd footer
data
data
5th header
data
6th header
data
6th footer
5th footer
data
2nd footer
data
data
1st footer
1 1st header
2 data
3 2nd header
4 data
5 3rd header
6 4th header
stack: 6
5
3
1
7 data
8 4th footer: Indent (6+1) to (8-1):: (7) to (7):: i.e., one line is indented
stack: 5
3
1
9 data
10 3rd footer: Indent (5+1) to (10-1):: (6) to (9):: i.e., indent 4 lines
11 data
At this point we have:1 1st header
2 data
3 2nd header
4 data
5 3rd header
6 4th header
7 data
8 4th footer
9 data
10 3rd footer
11 data
12 data
...Begin
Begin
...If
Start of
For
The peculiar thing is that the ... acts as a single character when I move the cursor....End
End
And for simplicity, I have no trouble making them all:Begin
End
The "Labels" sheet indicates that headers will begin with one of these words:
The attached spreadsheet has a sheet called "Labels". Column A shows typical keywords and expressions that denote the start of a nested data structure, and Column B denotes the end of that data structure.
begin
if
loop
and footers will begin with this word:end
The data is already indentedI checked again. The data was not indented. Very confused now.
The operation will cause some merged cells to unmerge. Do you wish to continue?I hit OK and more of the same. More OK's. I mean I would like to see the indentation.
Unable to set the ColumnWidth property of the Range class.And this popup has a Debug button.
The data is already indentedI checked again. The data was not indented.
The data is already indentedThat only appears after you click the 'Indent' button and some cell in column 'A' is blank.
I added the tags manually, and hit Manual Indent. Weird popup...I believe that's a misunderstanding. After adding the tags totally by hand, or using 'Add Tags', you should click the 'Indent' button as normally, and not 'Manual Indent'. The purpose of 'Manual Indent' is to allow you to select a few rows and then indent or outdent them.
->> The data is already indentedJust the 'Indent' button or Ctrl+Shift+I, both of which call the same code.
Which operations can produce this message?
I can ask another question similar to this but without the extra complexity of having some columns merged and other columns not merged.Sure. Is your question about Word, resolved?
How do you use the chr(13) to do the global replace?and I wanted to know if my answer to that question worked.
To avoid confusion on my part, and mine I assume you'll be doing that.
With as simple a problem as this one, your stack structure can be an integer variable. You might indent as you iterate the rows.This design comment set the stage for an implementation.
Private Sub Elip()
Dim lIndentLevel As Long
Dim oCell As Range
Dim sVal As String
Dim sTrim As String
Application.ScreenUpdating = False
For Each oCell In Worksheets("Fix").UsedRange.Columns(1).Cells
sVal = LCase(CStr(oCell.Value))
' look for horizontal ellipse
If InStr(1, sVal, Chr(133)) > 0 Then
sVal = "..." & Mid$(sVal, 2)
If Mid(sVal, 4, 1) = " " Then
' Delete one or more spaces following the 3 periods
Do
Loop Until Mid(sVal, 4, 1) = " "
End If
End If
If sVal Like "?end*" Or sVal Like "???end*" Or sVal Like "end*" Then
lIndentLevel = lIndentLevel - 1
End If
If lIndentLevel < 0 Then lIndentLevel = 0
If lIndentLevel > 0 Then
oCell.Resize(, lIndentLevel).Insert xlToRight
End If
If (sVal Like "?begin*" Or sVal Like "begin*" Or sVal Like "???begin*" _
Or sVal Like "?if *" Or sVal Like "if *" Or sVal Like "???if *" _
Or sVal Like "?for *" Or sVal Like "for *" Or sVal Like "???for *") Then
lIndentLevel = lIndentLevel + 1
End If
Next
Application.ScreenUpdating = True
End Sub
Begin repeated for
Begin for each
End repeat for
If
End if
Begin If
End repeat for each parameter...End repeat for each parameter
With as simple a problem as this one, your stack structure can be an integer variable. You might indent as you iterate the rows.