Changed number format - not getting the scenario issue - perhaps post the workbook.
Sub Loopthroughdirectory()
Dim wbk As Workbook
Dim Filename As String
Dim Path As String
Dim I As Integer
I = 1
Path = Application.GetOpenFilename(, , "Select a file in the Folder you want to list", , False)
Path = Left(Path, InStrRev(Path, "\"))
Filename = Dir(Path & "*.xls*")
'--------------------------------------------
With ActiveCell
.Value = "Serial #"
.Offset(0, 1).Value = "File Name"
.Offset(0, 2).Value = "Sales Values"
.Offset(0, 3).Value = "Hyperlinks"
.Resize(1, 4).Font.Bold = True
End With
Do While Len(Filename) > 0
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = I
If InStr(1, Filename, "_") <> 0 Then
ActiveCell.Offset(0, 1).Value = Left(Filename, InStr(1, Filename, "_") - 1)
ElseIf InStr(1, Filename, "(") <> 0 Then
ActiveCell.Offset(0, 1).Value = Left(Filename, InStr(1, Filename, "(") - 1)
ElseIf InStr(1, Filename, ".") <> 0 Then
ActiveCell.Offset(0, 1).Value = Left(Filename, InStr(1, Filename, ".") - 1)
Else
ActiveCell.Offset(0, 1).Value = Filename
End If
ActiveCell.Offset(0, 2).Formula = "='" & Path & "[" & Filename & "]sales'!$M$6"
ActiveSheet.Hyperlinks.Add Anchor:=ActiveCell.Offset(0, 3), Address:="" & Path & Filename & "", SubAddress:="sales!m6", TextToDisplay:=Filename
Filename = Dir
I = I + 1
Loop
Selection.CurrentRegion.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Offset(1, 2).Resize(Selection.Rows.Count - 1, 1).Cells.NumberFormat = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
Selection.Cells.EntireColumn.AutoFit
End Sub
Bookmarks