#1   Report Post  
Posted to microsoft.public.excel.misc
nc
 
Posts: n/a
Default Help with macro

The following macro list the file names in a specific directory on to a
worksheet named "TAS forms received" in column A and row 1. Each time it is
run overwrites the list.

What do I need to add to the macro so that the prior list is never
overwritten but the new file names in the directory are added at the end of
the list.

Thanks.


Private Sub Worksheet_Activate()

Dim FN As String ' For File Name
Dim ThisRow As Long
Dim FileLocation As String
Dim newWks As Worksheet


Set newWks = Worksheets("TAS forms received")

Application.ScreenUpdating = False



FileLocation = "F:\Finance\Transparency\Data collection\TAS forms
received\*.xls"

FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
newWks.Cells(ThisRow, 1) = FN
FN = Dir
Loop

Application.ScreenUpdating = True

End Sub





  #2   Report Post  
Posted to microsoft.public.excel.misc
Bernie Deitrick
 
Posts: n/a
Default Help with macro

nc,

Change

FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
newWks.Cells(ThisRow, 1) = FN
FN = Dir
Loop


to

FN = Dir(FileLocation)
Do Until FN = ""
If IsError(Application.Match(FN, newWks.Range("A:A"), False)) Then
newWks.Cells(Rows.Count, 1).End(xlUp)(2).Value = FN
End If
FN = Dir
Loop

HTH,
Bernie
MS Excel MVP


"nc" wrote in message
...
The following macro list the file names in a specific directory on to a
worksheet named "TAS forms received" in column A and row 1. Each time it is
run overwrites the list.

What do I need to add to the macro so that the prior list is never
overwritten but the new file names in the directory are added at the end of
the list.

Thanks.


Private Sub Worksheet_Activate()

Dim FN As String ' For File Name
Dim ThisRow As Long
Dim FileLocation As String
Dim newWks As Worksheet


Set newWks = Worksheets("TAS forms received")

Application.ScreenUpdating = False



FileLocation = "F:\Finance\Transparency\Data collection\TAS forms
received\*.xls"

FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
newWks.Cells(ThisRow, 1) = FN
FN = Dir
Loop

Application.ScreenUpdating = True

End Sub







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Editing a simple macro Connie Martin Excel Worksheet Functions 5 November 29th 05 09:19 PM
Can T Get Macro To Run! Nipper New Users to Excel 2 November 4th 05 04:48 AM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"