Hi Thai,
Originally Posted by
Thainguyen
.. the way you coding your code is totally different then me
Yes, everybody writes differently so understanding somebody else code is almost always difficult.
I am happy to explain in as much detail any part of my coding. Just ask at anytime for more explanation.
The code technique, VBA arrays, which I am using might not be familiar to you. If you are not familiar with arrays, then think of arrays as extra Worksheets that only VBA can see. These “array sheets” cannot be manipulated as we can in Normal Worksheets because we cannot look at them in the same way that we can look at normal worksheets. They can only be manipulated by VBA code.
I begin by transferring all the data I need from the normal Worksheets into the initial two arrays,
arrSht1() = Ws1.Range("B1:G" & Lr1 & "").Value
arrSht2() = Ws2.Range("B1:G" & Lr1 & "").Value
I use various other arrays in the coding.
The main purpose of the code is to fill a final array, arrOut(). This final array contains the output you want. Once this is filled fully , then the entire contents of the array is pasted out in one go, in a code line looking something like this, where we adjust a Worksheet range to the size of the array, .Resize(UBound(arrOut(), 1), UBound(arrOut(), 2) , and then assign the values in the cells of the Worksheet range to the values in the array
………range …. ___ .Resize(UBound(arrOut(), 1), UBound(arrOut(), 2)).Value = arrOut()
_.________________________________________________ __
So moving on with adjusting the output to look as you wish.
To adjust this, we primarily need to change the information which the code puts in the Output array, arrout(). In other words we need to change how the code is manipulating the contents of the “hidden array sheet”, arrOut()
I suggest I give you a couple of alternatives. I will not explain them in such detail now until we have decided what output you prefer, and made any further adjustments. As I said before I will happily explain anything in a lot more detail if you ask
Alternative 1
I will use a slightly different set of test data to that which you gave in the screenshot above in Post #15. The reason for me doing this is
_1) that it will demo slightly better the two different possibilities in output data.
_2) I expect you may have intended to include in Sheet2, the data for 2 Jet Blue21 ABC 458 458. Without this data, then this will be Missing data. So without this data in Sheet2 , then I do not think your suggested output in the screenshot in post #15 is correct. I may have misunderstood. You need to clarify this…
So my start point is the data I suggest here:
http://www.excelfox.com/forum/showth...0756#post10756
In the last code , ( Sub Testies ), the following output is obtained:
http://www.excelfox.com/forum/showth...0757#post10757
So here we go..
We have currently output like this:
Test Output |
Test Output |
Test Output |
Test Output |
Test Output |
2 |
Jet Blue23 |
ABC |
DEF |
DEF |
But We want this to look more similar to screenshot output from post #15 ( http://www.excelfox.com/forum/showth...0754#post10754 )
To do this I have included a new code section, Rem3c, for a new, Third Loop @@@@@@
Briefly, this looks at the current state of each “row” in arrout().
___ If we have an entry that is not containing Missing then we add a check to see If the data is the same as in Sheet1 for the current loop row. When this is not the case this is indicated in the required _ “ xyz < > ABC “ _ type format
This code snippet is approximately the code part that does this. (I can explain in more detail anything when / if you ask):
Code:
If InStr(1, arrOut(Cnt, 1), "MISSING:", vbBinaryCompare) <> 1 Then
'3c(ii) Loop across columns in output array
For Cntx = 1 To 2 ' .....we need to break up into two loops, as we have columns in Output array of 1 2 3 4 5 but in Input array for sheet 1 we have B C D E F G .. D is ignored,
If arrOut(Cnt, Cntx) <> "" And arrOut(Cnt, Cntx) <> CStr(arrSht1(Cnt, Cntx)) Then ' condition for changed data
arrOut(Cnt, Cntx) = CStr(arrSht1(Cnt, Cntx)) & " < > " & arrOut(Cnt, Cntx)
Here is this next complete test code: http://www.excelfox.com/forum/showth...0758#post10758
Here is test output: http://www.excelfox.com/forum/showth...0759#post10759
_.________________________________________________ _
Alternative 2
I will add this possibly later, in a new post, depending on how we decide to take this further.
_.___________________________
Alan
_._______________________________
P.s. I still need an answer to this question:
Originally Posted by
DocAElstein
P.S.
Note:
Note one extra point you may need to consider
Take the scenario of two things happening at the same time
_ that on sheet2 ( NEW ) there is new data on say, row 3
_ the data from row 3 on sheet1 ( Original) is not anywhere in sheet2 ( NEW )
In my current coding this scenario will result in the Missing data being indicated in the corresponding for row 3 in the output results. In such a scenario, the new data in row 3 on sheet2 ( NEW ) will not be indicated.
You must think about this and decide what info you want displayed on the output ( the missing or new data ) , or both. Possibly you have not thought of this scenario?
I may not have explained to well the question.
I will possibly try to explain again later
We can leave this question for now and answer it later.
Bookmarks