ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Collapse away VBA lines with deep indentation (https://www.excelbanter.com/excel-programming/431884-collapse-away-vba-lines-deep-indentation.html)

Paul

Collapse away VBA lines with deep indentation
 
In vi/vim, one can collapse away code of a certain level of
indentation (and all subordinate levels). Is there a way to do this
in the VB editor? Without such a feature, it's rather hard to see
which code belongs within which flow control structures when the code
runs over a page long.

ryguy7272

Collapse away VBA lines with deep indentation
 
Jacob Skaria helped me with this a few months back:

Dim arrINT(10) As Long
Sub GroupbyIndexLevels2()
Dim lngRow As Long
Dim intCIL As Integer
Dim intPIL As Integer
For lngRow = 1 To Cells(Rows.Count, "B").End(xlUp).Row
intCIL = Range("B" & lngRow).IndentLevel
If intCIL 0 Then
If intCIL intPIL Then
arrINT(intCIL) = lngRow
ElseIf intCIL < intPIL Then
GroupRows2 intCIL, lngRow
End If
intPIL = intCIL
End If
Next lngRow
GroupRows2 1, lngRow
ActiveSheet.Outline.ShowLevels RowLevels:=1
End Sub

Sub GroupRows2(intIND As Integer, lngRow As Long)
Dim intTemp As Integer
For intTemp = intIND + 1 To UBound(arrINT)
If arrINT(intTemp) < 0 Then
Rows(arrINT(intTemp) & ":" & lngRow - 1).Group
arrINT(intTemp) = 0
End If
Next
End Sub


Sub UnGrp()
Range("A1").Select
Selection.ClearOutline
End Sub

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Paul" wrote:

In vi/vim, one can collapse away code of a certain level of
indentation (and all subordinate levels). Is there a way to do this
in the VB editor? Without such a feature, it's rather hard to see
which code belongs within which flow control structures when the code
runs over a page long.


Norie

Collapse away VBA lines with deep indentation
 
You could just select all the code and use SHIFT+TAB or EditOutdent.

Mind you isn't it easier to follow code that is well indented?

If the problem is that it's badly indented then there are add-ins that
can help.

Personally if I have to deal with badly indented code I just remove
all the indentation and then redo it.

Sometimes that actually helps, for me anyway, in understanding the
flow/structure.



All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com