?
Solved

Compare 2 MSHFlexgrid VB6

Posted on 2011-03-11
10
Medium Priority
?
1,010 Views
Last Modified: 2012-05-11
Hello all,

I need to be able to compare 2 MSHFlexgrid.  MSHFlexgrid1 and MSHFlexgrid2.

In the picture bellow, MSHFlexgrid1 at the top and MSHFlexgrid2 under.

I need to see if column 0 text and Column 1 text and Column 6 from the same row, is showing in  MSHFlexgrid2 column 0 .text and Column 2 .text and Column 5.

If there is no match, then it will put in column 14 of the same row "NEEDS TO BE REMOVED".

How can i do this please?

Thanks
Compare-grig.JPG
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 35108171
Are both of these being populated from an Excel file as previous questions?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 35108232
Hello Brook1966

Yes, the where populated from 2 different excel  spreadsheet.
0
 
LVL 14

Accepted Solution

by:
VBClassicGuy earned 2000 total points
ID: 35108829
This is an easy one...

Dim r1 As Long, r2 As Long
Dim test1 As String, test2 As String, test3 As String

For r1 = 1 To MSHFlexGrid1.Rows -1
   test1 = MSHFlexGrid1.TextMatrix(r1, 0)
   test2 = MSHFlexGrid1.TextMatrix(r1, 1)
   test3 = MSHFlexGrid1.TextMatrix(r1, 6)
   For r2 = 1 To MSHFlexGrid2.Rows - 1
      If test1 = MSHFlexGrid2.TextMatrix(r2, 0) Then
         If test2 = MSHFlexGrid2.TextMatrix(r2, 2) Then
            If test3 = MSHFlexGrid2.TextMatrix(r2, 5) Then
               MSHFlexGrid1.TextMatrix(r1, 14) = "NEEDS TO BE REMOVED"
               Exit For
            End If
         End If
      End If
   Next r2
Next r1
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Author Comment

by:Wilder1626
ID: 35109136
ok , i will try this now and let you know.

Thanks again
0
 
LVL 14

Expert Comment

by:VBClassicGuy
ID: 35109404
I just noticed something. Your textual explanation of what you need to do doesn't match your picture. You say grid1 column 1 needs to be compared with grid2 column 2, but your picture's arrow is pointing from column 1 to column 1.

If the picture is the correct way you want to compare, change this line:

If test2 = MSHFlexGrid2.TextMatrix(r2, 2) Then

to

If test2 = MSHFlexGrid2.TextMatrix(r2, 1) Then

0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 35109465
Wilder...looking back to your previous question, I showed you how to add a formula to the importing worksheet....
Example:
dim sFormula as string
sFormula = "=IF(RC[" & C1 & "]=R[-1]C[" & C1 & "],IF(RC[" & C2 & "]=R[-1]C[" & C2 & "],IF(RC[" & C3 & "]=R[-1]C[" & C3 & "],1,0),0),0)"
This was to create an ending column and set the value 1 when the previous row was a duplicate...

In the same context...

dim sLookUp as string
dim sDOC as string ' THE PATH AND NAME OF YOUR 2ND EXCEL
sDOC = "'C:\Documents and Settings\All Users\Desktop\[kewl.xls]Sheet1'"

For i = 2 To NoOfRows
   sLookUp = "=IF(VLOOKUP(RC[-9]," & sDOC & "!R[-" & i-1 & "]C[-9]:R[" & NoOfRows - i & "]C[-9],1,FALSE)<>""""," & _
             "=IF(VLOOKUP(RC[-7]," & sDOC & "!R[-" & i-1 & "]C[-7]:R[" & NoOfRows - i & "]C[-7],1,FALSE)<>""""," & _
             "=IF(VLOOKUP(RC[-3]," & sDOC & "!R[-" & i-1 & "]C[-3]:R[" & NoOfRows - i & "]C[-3],1,FALSE)<>"""",""REMOVE"",""""),""""),"""")"
   xlWB.Worksheets(1).Cells(i, 14).FormulaR1C1 = sLookUp
End if

Open in new window

0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 35109482
VB Classic has a very good solution but based on the size of Grid1 and Grid2, that could take a very long time to run...
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 35109546
oh...by the way....knowing that your excel sheets come from external sources...
you will have to tweek the RC values to the Columns you want to compare against...
These values represent my sample that we talked about before where -9 is ( columns to the left of where the REMOVE should go...
In your case these values should be... -14, -13 and -8 for the look up and -14,-13 and -9 on the 2nd sheet
sLookUp = "=IF(VLOOKUP(RC[-14]," & sDOC & "!R[-" & i-1 & "]C[-14]:R[" & NoOfRows - i & "]C[-14],1,FALSE)<>""""," & _
          "=IF(VLOOKUP(RC[-13]," & sDOC & "!R[-" & i-1 & "]C[-13]:R[" & NoOfRows - i & "]C[-13],1,FALSE)<>""""," & _
          "=IF(VLOOKUP(RC[-8]," & sDOC & "!R[-" & i-1 & "]C[-9]:R[" & NoOfRows - i & "]C[-9],1,FALSE)<>"""",""REMOVE"",""""),""""),"""")"

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 35110646
OK, i will work on it and let you know the result.

Thanks again
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 35121760
Hello all,

After some testing, this code is what i need.

Thanks to both of you for your help.

Have a great weekend.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question