Solved

VB6 convert MSHFlexgrid1 cells

Posted on 2016-07-25
7
51 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
  • 4
  • 3
7 Comments
 
LVL 45

Expert Comment

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

Author Comment

by:Wilder1626
Comment Utility
wow, sorry, here it is.
Projet1.zip
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
The zip only contains the vbp file. I need the whole thing, or at least Form1.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 11

Author Comment

by:Wilder1626
Comment Utility
That zip will do. sorry again :)
Projet1.zip
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
You are right about the CAD / CAN

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

Expert Comment

by:Martin Liss
Comment Utility
As always...
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now