Solved

VB6 convert MSHFlexgrid1 cells no2

Posted on 2016-07-26
2
57 Views
Last Modified: 2016-07-27
Hi,

This topic follow the previous one on this link:
https://www.experts-exchange.com/questions/28959455/VB6-convert-MSHFlexgrid1-cells.html?anchor=a41728752#a41728752

I need to add 1 small thing to previous code when in column 4, i need to add a sequence number.

Just as a recap:
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 3 of the first row only.
Then, it will empty the value in column 2 and add the letter "D" in column 2.

Now i want to add in column 4 the sequence number always matching column 0, 1 and 11 combination.

Ex:

Before:
before
After macro:
after_result
How can i do that?

Thanks for your help
Filter-grid.zip
0
Comment
Question by:Wilder1626
2 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41730689
Private Sub Command2_Click()
    Dim strOldKey As String
    Dim lngRow As Long
    Dim lngD As Long
    Dim lngStartRow As Long
    Dim intSeq As Integer
    
    strOldKey = MSHFlexGrid1.TextMatrix(1, 0) & MSHFlexGrid1.TextMatrix(1, 1) & MSHFlexGrid1.TextMatrix(1, 11)
    lngStartRow = 1
    intSeq = 1
    MSHFlexGrid1.TextMatrix(lngStartRow, 3) = "H"
    MSHFlexGrid1.TextMatrix(lngStartRow, 4) = intSeq
    
    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"
            intSeq = 1
            For lngD = lngStartRow + 1 To lngRow - 1
                MSHFlexGrid1.TextMatrix(lngD, 2) = ""
                MSHFlexGrid1.TextMatrix(lngD, 3) = "D"
                intSeq = intSeq + 1
                MSHFlexGrid1.TextMatrix(lngD, 4) = intSeq
            Next
            lngStartRow = lngRow
            strOldKey = MSHFlexGrid1.TextMatrix(lngStartRow, 0) & MSHFlexGrid1.TextMatrix(lngStartRow, 1) & MSHFlexGrid1.TextMatrix(lngStartRow, 11)
        End If
    Next
    intSeq = 1
    MSHFlexGrid1.TextMatrix(lngStartRow, 4) = intSeq
    For lngD = lngStartRow + 1 To lngRow - 1
        MSHFlexGrid1.TextMatrix(lngD, 2) = ""
        MSHFlexGrid1.TextMatrix(lngD, 3) = "D"
        intSeq = intSeq + 1
        MSHFlexGrid1.TextMatrix(lngD, 4) = intSeq
    Next
End Sub

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 41730988
And again, it does exactly what i wanted.
 Thank you again and again!!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now