espenskeie
Well-known Member
- Joined
- Mar 30, 2009
- Messages
- 636
- Office Version
- 2016
- Platform
- Windows
Hello
I have a problem with this code, when it checks if the file exists, and if it doesn't, the code ends up going in a loop on that For i = 2 etc etc all the time, it cannot move to next i
Does anyone have a suggestion?
This is the beginning of my code, and heres how it ends:
So the If Dir.... code ends up at the bottom with just an End If. And the thougt was to go back in line and pull the next i.
Regards
Espen
I have a problem with this code, when it checks if the file exists, and if it doesn't, the code ends up going in a loop on that For i = 2 etc etc all the time, it cannot move to next i
Does anyone have a suggestion?
Code:
For i = 2 To lr1
which_file = (Sheets("1HourHL").Range("V2") & "_" & _
Sheets("1HourDATA").Range("D" & i) & "_" & Sheets("1HourHL").Range("AB2"))
which_string = Desktop & "Intraday\Textfiles\" & which_file & ".txt"
highval = Sheets("1HourHL").Range("F" & i).Value
lowval = Sheets("1HourHL").Range("G" & i).Value
If Dir(which_string) <> "" Then
Workbooks.OpenText Filename:= _
which_string _
, Origin:=xlMSDOS, startrow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), _
TrailingMinusNumbers:=True
This is the beginning of my code, and heres how it ends:
Code:
If sh3.Range("AC" & i).Value = "Short" Then
If sh3.Range("Q" & i).Value < sh3.Range("R" & i).Value Then
sh3.Range("AD" & i).Formula = "=(N" & i & "-P" & i & ")"
sh3.Range("AE" & i).Formula = "=(AD" & i & "/N" & i & ")"
sh3.Range("AG" & i).Value = "ExitTimeShort"
ElseIf sh3.Range("Q" & i).Value > sh3.Range("R" & i).Value Then '''''' Her slår stoplossen inn
sh3.Range("AD" & i).Formula = "=(N" & i & "-R" & i & ")"
sh3.Range("AE" & i).Formula = "=(AD" & i & "/N" & i & ")"
sh3.Range("AG" & i).Value = "StopShort"
End If
End If
'**************************************************************************************
wb1.Close False
End If
Next
So the If Dir.... code ends up at the bottom with just an End If. And the thougt was to go back in line and pull the next i.
Regards
Espen