Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6909403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:41:05+00:00 2026-05-27T08:41:05+00:00

On an Excel sheet, Col A has many thousands of rows that are sorted

  • 0

On an Excel sheet, Col A has many thousands of rows that are sorted and formatted like this:

C:\\Folder1\Folder2\fileA
C:\\Folder1\Folder2\fileB
C:\\Folder1\Folder2\Folder3\fileC
C:\\Folder1\Folder2\Folder3\fileD
C:\\Folder1\Folder2\Folder3\fileE
C:\\Folder1\Folder2\Folder4\Folder5\fileF
C:\\Folder1\Folder2\Folder4\Folder5\fileG

and I’d like to convert to this:

C:\\Folder1\Folder2\
fileA
fileB

C:\\Folder1\Folder2\Folder3\
fileC
fileD
fileE

C:\\Folder1\Folder2\Folder4\Folder5\
fileF
fileG

etc.

I’d prefer to do it with VBA if possible.

Then, with that done, there will frequently be folders that have so many enclosed files that the list extends beyond one screen height, and so there’s no indication of which folder the visible files belong to. I’d like to extract the path of the last folder that scrolled off screen at the top, and maybe put it into a var that gets updated with the scroll, then I’ll put that on a TextBox and leave it out for reference.

Ok, that last part looks hard, but full marks if you can help me get the first part done.

  • Thanks
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:41:06+00:00Added an answer on May 27, 2026 at 8:41 am

    This should work for you. Since there is no event to capture when the user scrolls, the folder “header row” is repeated every 20 rows if necessary.

    Sub ReformatCells()
        Dim lRow As Long
        Dim lRowStart As Long
        Dim sPath As String
        Dim sFolderPrev As String
        Dim sFolderCur As String
        Const MAX_ROW_SECTION As Long = 20
    
        With ActiveSheet
            lRow = 0                  ' row before first row to format
            sPath = "start"           ' any non-zero-length string
            sFolderPrev = CStr(Timer) ' value guarenteed not to match
            Do While Len(sPath) > 0
                lRow = lRow + 1
                sPath = .Cells(lRow, 1).Value
                sFolderCur = GetFolder(sPath)
                If sFolderCur <> sFolderPrev Then
                    ' new folder, so insert a blank row and "header row"
                    .Rows(lRow).Insert
                    .Rows(lRow).Insert
                    lRow = lRow + 1
                    lRowStart = lRow
                    .Cells(lRow, 1) = sFolderCur
                    sFolderPrev = sFolderCur
                    lRow = lRow + 1
                    .Cells(lRow, 1) = Mid$(sPath, Len(sFolderPrev) + 1)
                Else
                    If lRow - lRowStart >= MAX_ROW_SECTION Then
                        ' repeat folder header
                        .Rows(lRow).Insert
                        .Cells(lRow, 1) = sFolderPrev & " (cont)"
                        lRowStart = lRow
                        lRow = lRow + 1
                    End If
                    ' just trim off the folder
                    .Cells(lRow, 1) = Mid$(sPath, Len(sFolderPrev) + 1)
                End If
            Loop
        End With
    End Sub
    Function GetFolder(sPath As String) As String
        Dim iPos As Integer
        iPos = InStrRev(sPath, "\")
        If iPos > 0 Then
            GetFolder = Left$(sPath, iPos)
        Else
            GetFolder = sPath
        End If
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel sheet that looks like this: |A B C D -----------------------------------------------------------------------------------
I have an Excel sheet and have this formula below. I would like to
I have an Excel sheet and have this formula below. I would like to
If I have two rows in an Excel (.xls) sheet, like a key-value pair,
I have an excel sheet full of times. They are formatted so that they
My excel sheet contains many columns and many rows. I want the program to
I have a excel sheet which has around 5000 rows in it.I have used
In my Excel sheet with column Changeset I am getting the changeset like: C:\ccviews\hgdasdff-9302\dfcsz\ahgrt\kjhssl\ASGHLS@@\main\ajsdkljlat\hahdasdhfk\1\test.txt\sub\hsdaklfl\3
In a cell in Excel sheet I have a Date value like: 01/01/2010 14:30:00
I have an excel sheet that I want to load into a datatable withe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.