I have a folder that contains hundreds of subfolders. The first four characters of each subfolder's name consists of a 4-digit number followed by a string of alphanumeric characters (Example: 1234_Test_test_99
).
I am trying to get the subfolder's full name (as indicated in the example) based on first four characters (in this case, I enter 1234
in cell C3 and expect to see 1234_Test_test_99
in cell F3).
Private Sub Worksheet_Change(ByVal Target As Range)
Folder = Dir("C:\Users\TestFolder" & Range("C3").Value & "*", vbDirectory)
If Len(Folder) > 0 Then
Range("F3").Value = Folder
Else
MsgBox("No such folder")
End If
End Sub
Upon entering the substring in C3, the subfolder's full name is briefly displayed in cell F3. A split second later, Excel crashes. No error message. It shuts down, closing all open files in the process. I believe the problem is at
Range("F3").Value = Folder
since after replacing it with
MsgBox(Folder)
the macro runs.