I'm sure this is something simple but I can't figure it out for the life of me. I have the variable "bob" which contains custom ranges based on the file name. An example value of "bob" shows as follows:
"-10", "-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0", " "
If I hardcode the exact same information into the activesheet.range section it works exactly as it is supposed to. But if I put in the variable (when stepping through I have verified that the variable does hold the correct values) instead it simply does not work. What am I doing wrong?
Also here is a portion of the code being used. with the location in question in bold
"-10", "-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0", " "
If I hardcode the exact same information into the activesheet.range section it works exactly as it is supposed to. But if I put in the variable (when stepping through I have verified that the variable does hold the correct values) instead it simply does not work. What am I doing wrong?
Also here is a portion of the code being used. with the location in question in bold
Code:
Dim DirFile As String
Dim tFile As String, bFile As String, c As Range, s As String, bob As String
Dim tblBuypos As New ADODB.Recordset
Dim sqlstatement As String
sqlstatement = "exec dmsp_getBuypos"
myADOConnection.Execute (sqlstatement)
sqlstatement = "select subdirectory,stores,startposbuy,minbuy from [directorytree3] join [buypos] on left([directorytree3].subdirectory,7)= [buypos].stores"
Set tblBuypos = myADOConnection.Execute(sqlstatement)
'tblBuypos.MoveFirst
While Not tblBuypos.EOF
tFile = tblBuypos.Fields("subdirectory")
bFile = Left(tFile, Len(tFile) - 4)
s = tblBuypos.Fields("startposbuy")
bob = tblBuypos.Fields("minbuy")
DirFile = "\\dmserver\shared\polling\ftproot\hold\buy\" & tFile
If Len(Dir(DirFile)) = 0 Then
MsgBox "File does not exist!"
Else
Workbooks.OpenText Filename:= _
"\\dmserver\shared\polling\ftproot\hold\buy\" & tFile, Origin:=437, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, 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), Array(8, 1), Array(9, 1), _
Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array( _
16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), _
Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array( _
29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), Array(35, 1), _
Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array(41, 1), Array( _
42, 1), Array(43, 1), Array(44, 1)), TrailingMinusNumbers:=True
Cells.Select
ActiveWorkbook.Worksheets(bFile).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(bFile).Sort.SortFields.Add Key:=Range _
(s & "2:" & s & "129506"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(bFile).Sort
.SetRange Range("A1:AR129506")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns(s & ":" & s).Select
Selection.AutoFilter
ActiveSheet.Range("$" & s & "$1:$" & s & "$129506").AutoFilter Field:=1, Criteria1:=Array _
(bob), Operator:=xlFilterValues
Range(s & "2").Select
Range(s & "2:" & s & "150000").Select
Application.DisplayAlerts = False
Selection.EntireRow.Delete
Application.DisplayAlerts = True
Selection.AutoFilter
ChDir "\\dmserver\shared\polling\ftproot\hold\buy\test"
ActiveWorkbook.SaveAs Filename:="\\dmserver\shared\polling\ftproot\hold\buy\test\" & tFile, _
FileFormat:=xlText, CreateBackup:=False
ChDir "\\dmserver\shared\polling\ftproot\hold\buy"
Kill "\\dmserver\shared\polling\ftproot\hold\buy\" & tFile
Application.DisplayAlerts = False
ActiveWindow.Close (SaveChange = False)
tblBuypos.MoveNext
End If
Wend
Application.DisplayAlerts = False
Application.Quit