verify if range of files exist in folder

Gen Otmin

New Member
Joined
Mar 10, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have found a code by JoeMo from back at 2012 that I have used.
Now I need it in another place and here I have empty cells in the range from where I get the names to check if files exists.
This results in that the empty cells get marked green as the filenames found in the folder, and I can't figure out how to solve this.
I don't want the empty cells to be marked green as the found files.
Anyone who can help me with this?

VBA Code:
Sub LookForFiles()
Dim pStr As String, myFile As String, rng As Range, lrw As Long
Dim fList As Variant

pStr = ActiveWorkbook.Path & "\"

'pStr = "The Path to Your Folder Here" 'Path to folder including final \
lrw = Range("F" & Rows.Count).End(xlUp).Row
Set rng = Range("F2", "F" & lrw)
fList = rng.Value
For i = LBound(fList, 1) To UBound(fList, 1)
    myFile = Dir(pStr & fList(i, 1)) '& "*")
    If Not myFile = vbNullString Then
        rng.Cells(i).Interior.Color = vbGreen
    End If
Next i
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,

Not sure to fully understand ...
Following instruction is changing cell interior
VBA Code:
rng.Cells(i).Interior.Color = vbGreen
You can always modify it ...
But you do not explain what your final objective is ...
 
Upvote 0
Sorry to be vague in my question. As seen in the picture below the empty cells are marked green and I can't get it not be like that.
marked green.jpg

I have solved it with conditional formating, the problem is that when someone add a row in the middle of the table all rows below stops working.
marked green cond.jpg

Hence why I try this vba code that I have used in a couple of other places.
 
Upvote 0
You could test following
VBA Code:
If rng.Cells(i).Value <> "" Then rng.Cells(i).Interior.Color = vbGreen
 
Upvote 0
Solution
You could test following
VBA Code:
If rng.Cells(i).Value <> "" Then rng.Cells(i).Interior.Color = vbGreen
Thank you, I have tried way to complicated things to solve this. Coding is not my strong point.
 
Upvote 0
You are welcome.

Glad you could fix your problem
 
Upvote 0

Forum statistics

Threads
1,215,868
Messages
6,127,413
Members
449,382
Latest member
DonnaRisso

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top