Looping Question
Hi Ryan
OK. Now it is a bit more clear from your explanation of what you are trying
to acheive. You dont need a second loop anyway. I have modified the
code...Try and feedback. This is not been tested in full..might need some
modifications..but still the logic would be same.....
Sub Macro()
Dim intIndent As Integer
Dim intTemp As Integer
Dim lngRow As Long
Dim arrIndent() As Long
ReDim arrIndent(6)
For lngRow = 1 To Cells(Rows.Count, "B").End(xlUp).Row
If Range("B" & lngRow).IndentLevel 0 And _
Range("B" & lngRow).IndentLevel < intIndent Then
intIndent = Range("B" & lngRow).IndentLevel
If arrIndent(intIndent) < Empty Then
Rows(arrIndent(intIndent) + 1 & ":" & lngRow - 1).Group
For intTemp = intIndent To 6: arrIndent(intTemp) = Empty: Next
Else
arrIndent(intIndent) = lngRow
End If
End If
Next lngRow
End Sub
If this post helps click Yes
---------------
Jacob Skaria
"ryguy7272" wrote:
Using the Mod operator is a great idea Jacob! Thats one that I didnt think
of until you put it out there. Unfortunately, something is still wrong here.
If I use Mod = 0, I get the odd IndentLines and if I use Mod = 1, I get the
even IndentLines. The code is definitely doing what I tell it do, but it is
still not doing what I need it to do. I want to group the odds AND evens. I
think the counter is fine and I think the loop is fine; I just need to do a
second loop, I think.
For instance, I have one cell with IndentLines = 2, which is on row 4. The
next time I have a cell with IndentLines = 2 is on row 1508. I would like to
see everything rolled up, or grouped, based on these LineIndents. Similarly,
row IndentLines = 3 on row 5. The next cell with IndentLines = 3 is row
1500. I would like to see everything between these rows grouped. In the
same fashion, IndentLines = 4 on row 6 and The next time I have a cell with
IndentLines = 4 is on row 323. Id like to see everything between these
groups grouped.
Thanks again!
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.
"Jacob Skaria" wrote:
Hi Ryan
I have just modified your code to group the rows with an even indent level;
but I am not sure whether this is what you are looking for..(coz I am bit
confused with your first loop). Try and feedback so as to be clear...
Sub Grp()
Dim lngRow As Long
Sheets("Sheet3").Select
For lngRow = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Range("B" & lngRow) < "" And _
Range("B" & lngRow).IndentLevel 0 And _
Range("B" & lngRow).IndentLevel Mod 2 = 0 Then
Range("B" & lngRow).Rows.Group
End If
Next lngRow
End Sub
If this post helps click Yes
---------------
Jacob Skaria
"ryguy7272" wrote:
This code will go through the used range and do the grouping for the cells
with IndentLevels that are even. However, for IndentLevels that are odd,
there is no grouping. I tried a double-loop, like For i€¦Next i and For
j€¦Next j, but that didnt work.
Sub Grp()
Dim lngRow As Long
Sheets("Sheet1").Select
For i = 12 To 0 Step -2
For lngRow = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Range("B" & lngRow) < "" And Range("B" & lngRow).IndentLevel =
(i) Then
Range("B" & lngRow).Rows.Group
End If
Next lngRow
Next i
End Sub
What do I need to do to make this group both even Indents and odd Indents?
Thanks,
Ryan---
P.S., sorry for that other post...not sure how THAT happened...
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.
|