Solved

VB6 convert MSHFlexgrid1 cells no2

Posted on 2016-07-26
2
49 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 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
And again, it does exactly what i wanted.
 Thank you again and again!!!!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…

763 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

12 Experts available now in Live!

Get 1:1 Help Now