Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Profil ubytzika_senzuala
Femeie
22 ani
Vrancea
cauta Barbat
22 - 45 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [EXCEL] VBA Code to Group / Ungroup Rows in All Sheets Except Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 787


Sub Group_Rows_in_All_Sheets()
Application.ScreenUpdating = False

Dim xSheet As Worksheet
Dim arr As Variant

' #### sheets to skip
arr = Array( _
            "Title", _
            "Description", _
            "Instructions", _
            "Overview", _
            "Data", _
            "Factors" _
            )

rw1 = InputBox("Enter the first row you want grouped")
rw2 = InputBox("Enter the last row you want grouped")

For Each xSheet In ActiveWorkbook.Sheets

    If InArray(xSheet.Name, arr) Then
        GoTo SkipSheet
    End If

    xSheet.Activate
   
    ' #### check if rows not grouped, then group, otherwise ungroup
    If Rows(rw1 & ":" & rw2).OutlineLevel = 1 Then
        Rows(rw1 & ":" & rw2).Group
    ElseIf Rows(rw1 & ":" & rw2).OutlineLevel > 1 Then
        Rows(rw1 & ":" & rw2).Ungroup
    End If
   
    ' #### hide grouped rows (press number one) _
           this line won't return an error if there are no groups in the sheet

    xSheet.Outline.ShowLevels RowLevels:=1
   
SkipSheet:

Next

' #### activate the first sheet in the workbook
ActiveWorkbook.Worksheets(1).Activate

Application.ScreenUpdating = True
End Sub

' #### check if value is in array
Function InArray(ByVal pstrVal As String, ByVal pvntArray As Variant) As Boolean
    Dim lngIdx As Long
    For lngIdx = 0 To UBound(pvntArray)
        If (pstrVal = VBA.CStr(pvntArray(lngIdx))) Then
            InArray = True
            Exit Function
        End If
    Next lngIdx
    InArray = False
End Function


Source:


pus acum 11 luni
   
Pagini: 1  

Mergi la