0% found this document useful (0 votes)
3 views3 pages

VBA Coding

The document contains two VBA subroutines for Excel. The first subroutine, ListFolders, allows the user to select a folder and lists all subfolder names in the active worksheet. The second subroutine, UnhideNextFilteredRow, unhides the next hidden row after each visible cell in column A of the active worksheet.

Uploaded by

sachin ailani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

VBA Coding

The document contains two VBA subroutines for Excel. The first subroutine, ListFolders, allows the user to select a folder and lists all subfolder names in the active worksheet. The second subroutine, UnhideNextFilteredRow, unhides the next hidden row after each visible cell in column A of the active worksheet.

Uploaded by

sachin ailani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Sub ListFolders()

Dim ws As Worksheet

Dim folderPath As String

Dim folderName As String

Dim objFSO As Object

Dim objFolder As Object

Dim objSubFolder As Object

Dim row As Integer

' Select folder

With Application.FileDialog(msoFileDialogFolderPicker)

.Title = "Select Folder"

If .Show = -1 Then

folderPath = .SelectedItems(1) & "\"

Else

Exit Sub

End If

End With

' Set worksheet and headers

Set ws = ActiveSheet

ws.Cells.Clear

ws.Range("A1").Value = "Folder Name"

' Initialize FileSystemObject

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder(folderPath)

' Loop through subfolders

row = 2

For Each objSubFolder In objFolder.SubFolders


ws.Cells(row, 1).Value = objSubFolder.Name

row = row + 1

Next objSubFolder

MsgBox "Folder list created successfully!", vbInformation

End Sub
Sub UnhideNextFilteredRow()

Dim ws As Worksheet

Dim cell As Range

Dim lastRow As Long

Set ws = ActiveSheet

lastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row

' Loop through visible cells in column A (adjust if needed)

For Each cell In ws.Range("A1:A" & lastRow).SpecialCells(xlCellTypeVisible)

' Unhide the next row if it's hidden

If cell.Offset(1, 0).EntireRow.Hidden = True Then

cell.Offset(1, 0).EntireRow.Hidden = False

End If

Next cell

MsgBox "Next rows after visible data are now unhidden.", vbInformation, "Unhide Complete"

End Sub

You might also like