Yet Another For without Next Error
Sub Bubbles()
Dim MyFileSystem, MyFolder, f1, FilesQ, s, myFile, MyCake Set MyFileSystem = CreateObject("Scripting.FileSystemObject") Set MyFolder = MyFileSystem.GetFolder("C:\Documents and Settings\My Documents\Inventory Stuff") Set FilesQ = MyFolder.Files Dim xDate As Integer Dim xTime As Integer Let xDate = 0 Let xTime = 0 Dim DateInt As Integer Dim TimeInt As Integer Dim Cake As Boolean For Each f1 In FilesQ s = Split(f1.Name, "_", -1, vbTextCompare) Let Cake = (IsNumeric(s(1)) And IsNumeric(s(2))) * If Cake = False Then Next DateInt = CInt(s(1)) TimeInt = CInt(s(2)) If DateInt = xDate Then If TimeInt xTime Then 'Set DateInt = xDate 'Set TimeInt = xTime 'Set myFile = f1 End If End If Next f1 MyCake = MsgBox(myFile.Name, 65, "MsgBox Example") End Sub Whenever I run this, I get a "For without Next Error" on the starred line. I've tried making it a block with an End If, and things run if I comment it out. Why might this be? |
Yet Another For without Next Error
Sub Bubbles()
Dim MyFileSystem, MyFolder, f1, FilesQ, s, myFile, MyCake Set MyFileSystem = CreateObject("Scripting.FileSystemObject") Set MyFolder = MyFileSystem.GetFolder("C:\Documents and Settings\My Documents\Inventory Stuff") Set FilesQ = MyFolder.Files Dim xDate As Integer Dim xTime As Integer Let xDate = 0 Let xTime = 0 Dim DateInt As Integer Dim TimeInt As Integer Dim Cake As Boolean For Each f1 In FilesQ s = Split(f1.Name, "_", -1, vbTextCompare) Let Cake = (IsNumeric(s(1)) And IsNumeric(s(2))) If Cake < False Then DateInt = CInt(s(1)) TimeInt = CInt(s(2)) If DateInt = xDate Then If TimeInt xTime Then 'Set DateInt = xDate 'Set TimeInt = xTime 'Set myFile = f1 End If End If End If Next f1 MyCake = MsgBox(myFile.Name, 65, "MsgBox Example") End Sub -- --- HTH Bob (change the xxxx to gmail if mailing direct) wrote in message oups.com... Sub Bubbles() Dim MyFileSystem, MyFolder, f1, FilesQ, s, myFile, MyCake Set MyFileSystem = CreateObject("Scripting.FileSystemObject") Set MyFolder = MyFileSystem.GetFolder("C:\Documents and Settings\My Documents\Inventory Stuff") Set FilesQ = MyFolder.Files Dim xDate As Integer Dim xTime As Integer Let xDate = 0 Let xTime = 0 Dim DateInt As Integer Dim TimeInt As Integer Dim Cake As Boolean For Each f1 In FilesQ s = Split(f1.Name, "_", -1, vbTextCompare) Let Cake = (IsNumeric(s(1)) And IsNumeric(s(2))) * If Cake = False Then Next DateInt = CInt(s(1)) TimeInt = CInt(s(2)) If DateInt = xDate Then If TimeInt xTime Then 'Set DateInt = xDate 'Set TimeInt = xTime 'Set myFile = f1 End If End If Next f1 MyCake = MsgBox(myFile.Name, 65, "MsgBox Example") End Sub Whenever I run this, I get a "For without Next Error" on the starred line. I've tried making it a block with an End If, and things run if I comment it out. Why might this be? |
All times are GMT +1. The time now is 05:27 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com