PC Review


Reply
Thread Tools Rate Thread

Automate identifying if 200 plus files exist in a folder

 
 
Bob Maloney
Guest
Posts: n/a
 
      7th Oct 2007
Hi,

XL 2003

I found the following code from the newsgroup to check if a file exists in a
particular folder.


Sub MyTestFileExists()
Dim FName As String
FName = ThisWorkbook.Sheets("Sheet1").Range("A1").Text
If Dir(FName) = "" Then
Range("B1").Value = "Does not exist"
Else
Range("B1").Value = "Exists"
End If
End Sub

Code works great for one file.

Is it possible to amend this code to loop through a dynamic range,
(currently A1:A200, but will grow) to identify each filename and place the
results in the adjacent cell in column B (B1:B200)?

Any help appreciated.

Thanks

Bob
East Maitland
Australia


 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      7th Oct 2007
You can give this a subroutine a try...

Sub MyTestFileExists()
Dim C As Range
With ThisWorkbook.Sheets("Sheet3")
For Each C In .Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
If Dir(C.Text) = "" Then
C.Offset(0, 1).Value = "Does not exist"
Else
C.Offset(0, 1).Value = "Exists"
End If
Next
End With
End Sub

There is no need to specify the range... it will automatically look from A1
to the last used row in Column A.

Rick


"Bob Maloney" <(E-Mail Removed)> wrote in message
news:470887f8$0$14945$(E-Mail Removed)...
> Hi,
>
> XL 2003
>
> I found the following code from the newsgroup to check if a file exists in
> a particular folder.
>
>
> Sub MyTestFileExists()
> Dim FName As String
> FName = ThisWorkbook.Sheets("Sheet1").Range("A1").Text
> If Dir(FName) = "" Then
> Range("B1").Value = "Does not exist"
> Else
> Range("B1").Value = "Exists"
> End If
> End Sub
>
> Code works great for one file.
>
> Is it possible to amend this code to loop through a dynamic range,
> (currently A1:A200, but will grow) to identify each filename and place
> the results in the adjacent cell in column B (B1:B200)?
>
> Any help appreciated.
>
> Thanks
>
> Bob
> East Maitland
> Australia
>


 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      7th Oct 2007
Sub MyTestFileExists()
Dim FName As String

With ThisWorkbook.Sheets("Sheet1")
LastRow = .Cells(Rows.Count, "A"). _
End(xlUp).Row

For RowCount = 1 To LastRow
FName = .Range("A" & RowCount).Text
If Dir(FName) = "" Then
.Range("B" & RowCount).Value = _
"Does not exist"
Else
.Range("B" & RowCount).Value = _
"Exists"
End If
Next RowCount
End With
End Sub


"Bob Maloney" wrote:

> Hi,
>
> XL 2003
>
> I found the following code from the newsgroup to check if a file exists in a
> particular folder.
>
>
> Sub MyTestFileExists()
> Dim FName As String
> FName = ThisWorkbook.Sheets("Sheet1").Range("A1").Text
> If Dir(FName) = "" Then
> Range("B1").Value = "Does not exist"
> Else
> Range("B1").Value = "Exists"
> End If
> End Sub
>
> Code works great for one file.
>
> Is it possible to amend this code to loop through a dynamic range,
> (currently A1:A200, but will grow) to identify each filename and place the
> results in the adjacent cell in column B (B1:B200)?
>
> Any help appreciated.
>
> Thanks
>
> Bob
> East Maitland
> Australia
>
>
>

 
Reply With Quote
 
Bob Maloney
Guest
Posts: n/a
 
      7th Oct 2007
Thanks Rick and Joel,

Appreciate the prompt assistance.

Cheers

Bob

"Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
message news:%23aUr$(E-Mail Removed)...
> You can give this a subroutine a try...
>
> Sub MyTestFileExists()
> Dim C As Range
> With ThisWorkbook.Sheets("Sheet3")
> For Each C In .Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
> If Dir(C.Text) = "" Then
> C.Offset(0, 1).Value = "Does not exist"
> Else
> C.Offset(0, 1).Value = "Exists"
> End If
> Next
> End With
> End Sub
>
> There is no need to specify the range... it will automatically look from
> A1 to the last used row in Column A.
>
> Rick
>
>
> "Bob Maloney" <(E-Mail Removed)> wrote in message
> news:470887f8$0$14945$(E-Mail Removed)...
>> Hi,
>>
>> XL 2003
>>
>> I found the following code from the newsgroup to check if a file exists
>> in a particular folder.
>>
>>
>> Sub MyTestFileExists()
>> Dim FName As String
>> FName = ThisWorkbook.Sheets("Sheet1").Range("A1").Text
>> If Dir(FName) = "" Then
>> Range("B1").Value = "Does not exist"
>> Else
>> Range("B1").Value = "Exists"
>> End If
>> End Sub
>>
>> Code works great for one file.
>>
>> Is it possible to amend this code to loop through a dynamic range,
>> (currently A1:A200, but will grow) to identify each filename and place
>> the results in the adjacent cell in column B (B1:B200)?
>>
>> Any help appreciated.
>>
>> Thanks
>>
>> Bob
>> East Maitland
>> Australia
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate searching and then copying files to a folder using excel SP Microsoft Excel Programming 2 21st May 2009 10:23 PM
Explorer folder lists files which do not exist? =?Utf-8?B?U2ltb24gMTk3Mg==?= Windows XP Performance 11 29th Jan 2006 10:53 PM
Identifying a folder for temporary files -- %TEMP% or something else? robert.dodier@gmail.com Windows XP General 1 18th Nov 2005 08:19 PM
automate copying files to folder =?Utf-8?B?YmlsbA==?= Windows XP General 1 29th Sep 2004 09:58 PM
Need sample code to automate deletion of temp internet folder files upon logging of my web application Avinash Deolalikar Windows XP Internet Explorer 1 18th Feb 2004 02:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:58 AM.