MyFile = Dir(MyFolder)
Do While MyFile <> ""
Application.StatusBar = "Opening" & MyFile
Set wbk = Workbooks.Open(MyFolder & MyFile, True, True)
bFound = False
For Each ws In wbk.Sheets
If ws.Name = "Sheet 1" Then
Range("B2").Select 'This gives us the first cell
Do Until IsEmpty(ActiveCell)
For i = LBound(arr, 1) To UBound(arr, 1)
For j = LBound(arr, 2) To UBound(arr, 2)
If arr(i, j) <> "" And arr(i, j) <> ActiveCell.Value Then
For k = UBound(arr, 2) To j + 1 Step -1
arr(k, i) = arr(k - 1, i)
Next k
arr(i, j) = ActiveCell.Value
End If
If arr(i, j) = "" Then
arr(i, j) = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
End If
If arr(i, j) = ActiveCell.Value Then
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "" Then
Exit For
End If
Next j
If ActiveCell.Value = "" Then
Exit For
End If
Next i
Loop
End If
Next
Loop
As you can see in the image I have an array of 4 elements, I got these elements into the array by iterating through the second column of a worksheet called "Sheet 1" from a workbook called "food.xlsx" in a folder that the user choses by selection. after the array places every element from column 2 of sheet "Sheet 1" and then places these elements into column 1 of itself, our array looks like the following image...
We then move on to the next workbook called "food2.xlsx" which is located in the same folder. We look at column 2 of food2.xlsx. Column 2 of food2.xlsx has the exact same values at the exact same rows as column 2 of food.xlsx. The only difference is that in row 3 of column 2 in food2.xlsx, instead of having a value of "chocolate", there is a value of "vanilla". What am I trying to do is place "vanilla" in the location of the array where "chocolate" is currently located, this would be at arr(1,3). Then what I want is to push "chocolate" and every other value under it down one spot. So the array should end up like..
The part of the code that is NOT doing its job is the if statement that starts with "If arr(i, j) <> "" And arr(i, j) <> ActiveCell.Value Then"
IMPORTANT: I need this to work for any new encountered value, not just vanilla