Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Automate identifying if 200 plus files exist in a folder

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Automate identifying if 200 plus files exist in a folder

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" wrote in message
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Automate identifying if 200 plus files exist in a folder

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Automate identifying if 200 plus files exist in a folder

Thanks Rick and Joel,

Appreciate the prompt assistance.

Cheers

Bob

"Rick Rothstein (MVP - VB)" wrote in
message ...
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" wrote in message
...
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
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
Check if specifik folder exist. HH[_2_] Excel Programming 4 December 5th 06 09:11 AM
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
Create Folder If It Doesn't Exist Neutron1871 Excel Programming 4 May 6th 05 01:42 AM
Does folder exist problem Jeff Excel Programming 3 January 31st 05 03:22 PM
How to check if a folder/directory exist using VBA wellie Excel Programming 1 March 1st 04 02:24 AM


All times are GMT +1. The time now is 06:17 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"