If statement inside of Do While Loop

treyabrown

New Member
Joined
May 23, 2014
Messages
7
I am trying to perform a loop through a file folder and pull all of the file names and paste them in my range EXCEPT I want it to skip all files that have Zero Reading in the name. Any help?

In my code below I cannot get the If statement to skip all file names containing "Zero Reading" in the title.

Sub ListFiles()
ActiveWorkbook.Sheets("Comparison").Select
Range("NetworkFile").Select
F = Dir(Range("FilePath") & "*" & Range("FileFormat"))

Do While Len(F) > 0
If F = "*" & Range("ZeroReading") & "*" Then
Exit Do
End If
ActiveCell.Formula = F
ActiveCell.Offset(1, 0).Select
F = Dir()
Loop
Application.Calculate
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You can use the InStr function to see if it contains ZeroReading, i.e.
Code:
If InStr(F,"ZeroReading") > 0 Then
or if it does not include it, i.e.
Code:
If InStr(F,"ZeroReading") = 0 Then
 
Upvote 0
You can use the InStr function to see if it contains ZeroReading, i.e.
Code:
If InStr(F,"ZeroReading") > 0 Then
or if it does not include it, i.e.
Code:
If InStr(F,"ZeroReading") = 0 Then

Thank you! "=0" worked like a charm. Appreciate the quick response!
 
Upvote 0
You are most welcome!:)
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,636
Members
449,043
Latest member
farhansadik

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