I'm hoping I don't do this a lot. I'm in a small business again and the only vba person right now.
I can get a vertical array to populate and loop very nicely. Then there's an array from a horizontal range that isn't doing the same thing very well. Specifically I can not read from it in order to compare two arrays. I have tried Redim and Redim preserve but it doesn't seem to be helping much. Basically it looks like I'm loading the array variable but I can't access anything in it for comparison to the second array. I've also tried dimming a certain size and then redimming but that didn't seem to be any different.
The line that blows up right now is below. I can message box cell.value and see something there but if I try to loop to the value with I or anything else I get an error
Right now the error is subscript out of range but I also get object not available which I think are symptoms of the same issue.
'This is the line that's blowing up right now
CurrFormat(I) = Cell.Value
I can get a vertical array to populate and loop very nicely. Then there's an array from a horizontal range that isn't doing the same thing very well. Specifically I can not read from it in order to compare two arrays. I have tried Redim and Redim preserve but it doesn't seem to be helping much. Basically it looks like I'm loading the array variable but I can't access anything in it for comparison to the second array. I've also tried dimming a certain size and then redimming but that didn't seem to be any different.
The line that blows up right now is below. I can message box cell.value and see something there but if I try to loop to the value with I or anything else I get an error
Right now the error is subscript out of range but I also get object not available which I think are symptoms of the same issue.
'This is the line that's blowing up right now
CurrFormat(I) = Cell.Value
Code:
Sub CheckFileFormat()
Dim CorrectFormat() As Variant
Dim CurrFormat() As Variant
Dim CurrFileName As String
Dim Numrows As Integer
Dim NumCols As Integer
Dim I As Long
Dim x As Long
Dim Cell As Range
Dim rgFound As Range
Dir ("C:\Users\BMcEllistrem\Desktop\Imports\")
CurrFileName = Range("A2").Value
'If Range("F2").Value <> "" Then
ActiveWorkbook.Sheets("ColumnHeadings").Activate
Range("A1").End(xlToRight).Select
Set rgFound = Selection.Find(CurrFileName)
Range(rgFound, rgFound.End(xlDown)).Select
Numrows = Selection.Rows.Count
ReDim Preserve CorrectFormat(Numrows)
CorrectFormat() = Selection.Value
Workbooks.Open ("C:\Users\BMcEllistrem\Desktop\Imports\" & CurrFileName)
Range("A1", Range("A1").End(xlToRight)).Select
NumCols = Selection.Columns.Count
'ReDim Preserve CurrFormat(NumCols)
I = 1
For Each Cell In Selection
MsgBox Cell.Value
'This is the line that's blowing up right now
CurrFormat(I) = Cell.Value
I = I + 1
Debug.Print Cell.Value
Next Cell
'This does well. I can print and get rows and column counts.
Debug.Print "Correct format is " & LBound(CorrectFormat) & " " & UBound(CorrectFormat);
Debug.Print "Current format is " & LBound(CurrFormat) & " " & UBound(CurrFormat);
'This does not work well. I can get one loop to work but not both so I can't get to compare the two columns.
'The currformat is in a horizontal line the correct format array is in a vertical line.
For x = LBound(CurrFormat) To UBound(CurrFormat)
Debug.Print CurrFormat(x)
For I = LBound(CorrectFormat) To UBound(CorrectFormat)
Debug.Print CorrectFormat(I)
' If CorrectFormat(I, 1).Value = CurrFormat(1, I).Value Then
' Debug.Print "No problems"
' ElseIf CorrectFormat(I, 1) <> CurrFormat(1, I) Then
' Debug.Print "Correct format is " & CorrectFormat(I).Value & " Current format is " & CurrFormat(I).Value
' End If
Next I
Next x
MsgBox "Done checking " & CurrFileName
End Sub
[code]