Group rows in Excel using VBA

Group rows in Excel using VBA. Enter a long list of names in the appropriate spot for grouping. Check out my online courses www.easyexcelanswers.com/courses.html
All my courses include online support and a user manual
Let me teach you the VBA that I have learn in my five years of consulting

Let’s take the frustration out of user forms

Become an Affiliate and earn 25% on Course Sales

For more help visit my website www.easyexcelanswers.com or email me at [email protected].

Contact me regarding customizing this template for your needs.

Click for online Excel Consulting

I am able to provide online help on your computer at a reasonable rate.

I use a Blue condenser Microphone to record my videos, here is the link

Check out Crowdcast for creating your webinars

If you need to buy Office 2019 follow

I use Tube Buddy to help promote my videos
Check them out

Follow me on Facebook

TWEET THIS VIDEO

Follow me on twitter
easyexcelanswers

IG @barbhendersonconsulting

You can help and generate a translation to you own language

*this description may contain affiliate links. When you click them, I may receive a small commission at no extra cost to you. I only recommend products and services that I’ve used or have experience with.

code
Sub enteremployees()
Dim r, c As Long
Dim row As Long
Dim name, id As String
Dim cnt As Long

r = 4
c = 1
cnt = 1
Do While cnt less than 50
For row = 2 To 51
ActiveSheet.Cells(r, c).Select
ActiveCell.Value = Sheet7.Cells(row, 1).Value
ActiveCell.Offset(0, 1).Value = Sheet7.Cells(row, 1).Offset(0, 1).Value
cnt = cnt + 1
r = r + 6
Next row
Loop
End Sub

Sub Groupemployees()

Dim myrange As Range
Dim erow As Long, currentRow As Long
Dim firstBlankRow As Long, lastBlankRow As Long
Dim currentRowValue As String
Dim nextRowValue As String

Application.ScreenUpdating = False ‘Stop screen updating while grouping

‘specify the range
Set myrange = Range(“A4:A364”)
erow = Cells(Rows.Count, myrange.Column).End(xlUp).row

firstBlankRow = 0
lastBlankRow = 0

‘for every row in the range
For currentRow = 4 To erow
currentRowValue = Cells(currentRow, myrange.Column).Value
nextRowValue = Cells(currentRow + 1, myrange.Column).Value

If Not (IsEmpty(currentRowValue) Or currentRowValue = “”) Then
If (IsEmpty(nextRowValue) Or nextRowValue = “”) Then
firstBlankRow = currentRow + 1
End If
ElseIf (IsEmpty(currentRowValue) Or currentRowValue = “”) Then
If Not (IsEmpty(nextRowValue) Or nextRowValue = “”) Then
If firstBlankRow not equal to 0 Then
lastBlankRow = currentRow
End If
End If
End If
Debug.Print “Row ” & currentRow; “: firstBlankRow: ” & firstBlankRow; “, lastBlankRow: ” & lastBlankRow

If firstBlankRow not equal to 0 And lastBlankRow not equal to 0 Then

If Not ActiveSheet.Rows(currentRow).OutlineLevel greater than 1 Then
Range(Cells(firstBlankRow, myrange.Column), Cells(lastBlankRow, myrange.Column)).EntireRow.Select
Selection.Group
End If
firstBlankRow = 0: lastBlankRow = 0
End If
Next

Application.ScreenUpdating = True ‘Start screen updating as macro is complete
End Sub

Rate this post