Solved

VB6 convert MSHFlexgrid1 cells

Posted on 2016-07-25
7
85 Views
Last Modified: 2016-07-25
Hi,

I have this MSHFlexgrid1 where in Column 0,1 and 11, I may have multiple rows with the same values. Everything is already sorted by those 3 columns.

Using this:
    With MSHFlexGrid1
     .ColSel = 11
        .Sort = flexSortStringAscending
        .ColSel = 1
        .Sort = flexSortStringAscending
        .ColSel = 0
        .Sort = flexSortStringAscending
    End With

Open in new window


What i would like to do is that if i have multiple rows with the same value in column 0, 1 and 11, it will leave all cell populated  as it is and also add the letter "H" in column 4 of the first row only.
Then, it will empty the value in column 3 and add the letter "D" in column 4.

Example of the grid before the macro:
Before_sample
Then after the macro:
Macro_result
What would be the best way to do that as i can have up to 7000 rows in the grid.

I have put a sample of the project in attachment.

Thanks for your help
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
  • 3
7 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41728390
Can you supply a project zip file please?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 41728401
wow, sorry, here it is.
Projet1.zip
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41728407
The zip only contains the vbp file. I need the whole thing, or at least Form1.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Wilder1626
ID: 41728409
That zip will do. sorry again :)
Projet1.zip
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41728457
Note that in order to get your results I needed to change MSHFlexGrid1.TextMatrix(1, 11) = "CAD" in Form_Load to MSHFlexGrid1.TextMatrix(1, 11) = "CAN".
Private Sub Command2_Click()
    Dim strOldKey As String
    Dim lngRow As Long
    Dim lngD As Long
    Dim lngStartRow As Long
    
    strOldKey = MSHFlexGrid1.TextMatrix(1, 0) & MSHFlexGrid1.TextMatrix(1, 1) & MSHFlexGrid1.TextMatrix(1, 11)
    lngStartRow = 1
    MSHFlexGrid1.TextMatrix(lngStartRow, 3) = "H"
    
    For lngRow = 2 To MSHFlexGrid1.Rows - 1
        If MSHFlexGrid1.TextMatrix(lngRow, 0) & MSHFlexGrid1.TextMatrix(lngRow, 1) & MSHFlexGrid1.TextMatrix(lngRow, 11) <> strOldKey Then
            MSHFlexGrid1.TextMatrix(lngRow, 3) = "H"
            For lngD = lngStartRow + 1 To lngRow - 1
                MSHFlexGrid1.TextMatrix(lngD, 2) = ""
                MSHFlexGrid1.TextMatrix(lngD, 3) = "D"
            Next
            lngStartRow = lngRow
            strOldKey = MSHFlexGrid1.TextMatrix(lngStartRow, 0) & MSHFlexGrid1.TextMatrix(lngStartRow, 1) & MSHFlexGrid1.TextMatrix(lngStartRow, 11)
        End If
    Next
    For lngD = lngStartRow + 1 To lngRow - 1
        MSHFlexGrid1.TextMatrix(lngD, 2) = ""
        MSHFlexGrid1.TextMatrix(lngD, 3) = "D"
    Next
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 41728712
You are right about the CAD / CAN

Thanks a lot for your help. this works like a charm.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41728752
As always...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 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