[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VB6 convert MSHFlexgrid1 cells no2

Posted on 2016-07-26
2
Medium Priority
?
101 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
[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
2 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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

656 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