[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delete row if in MSHFlexGrid2

Posted on 2011-05-04
3
Medium Priority
?
402 Views
Last Modified: 2012-05-11
Hello all

I need your help to fix my code.

In my code bellow, i'm hiding all rows that don't match with my List1.

But what i want to do is to delete the row if it does not match with the list1.

How can i fix this please?

Thanks


 Dim lngRow As Long
    Dim lngListLoop As Long
    Dim dicUnique As New Scripting.Dictionary
    Dim lngRowHeight As Long
    Dim lngCount As Long
    
    lngRowHeight = MSHFlexGrid2.RowHeight(0)
    For lngListLoop = 0 To List1.ListCount - 1
        If List1.Selected(lngListLoop) Then
            dicUnique.Add List1.List(lngListLoop), 1
        End If
    Next
    Me.MousePointer = vbHourglass
    MSHFlexGrid2.Redraw = False
    For lngRow = 1 To MSHFlexGrid2.Rows - 1     'skip header row
        If dicUnique.Exists(MSHFlexGrid2.TextMatrix(lngRow, 1)) Then
            MSHFlexGrid2.RowHeight(lngRow) = lngRowHeight
            lngCount = lngCount + 1
        Else
            MSHFlexGrid2.RowHeight(lngRow) = 1  'hide
        End If
    Next
    MSHFlexGrid2.Redraw = True
    Me.MousePointer = vbDefault
    dicUnique.RemoveAll
    Set dicUnique = Nothing
    

Open in new window

0
Comment
Question by:Wilder1626
  • 2
3 Comments
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 35692245
Try this in place of your For Loop
lngRow = 1

    do while true
        If dicUnique.Exists(MSHFlexGrid2.TextMatrix(lngRow, 1)) Then
            MSHFlexGrid2.RowHeight(lngRow) = lngRowHeight
            lngCount = lngCount + 1
            lngRow = lngRow + 1
        Else
            MSHFlexGrid2.RowHeight(lngRow) = 1  'hide
            MSHFlexGrid2.RemoveItem(lngRow)
        End If
        if lngRow =  MSHFlexGrid2.Rows then exit do

    Next

Open in new window

0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 2000 total points
ID: 35692270
Whoops..left the Next statement in there :)
lngRow = 1

    do while true
        If dicUnique.Exists(MSHFlexGrid2.TextMatrix(lngRow, 1)) Then
            MSHFlexGrid2.RowHeight(lngRow) = lngRowHeight
            lngCount = lngCount + 1
            lngRow = lngRow + 1
        Else
            MSHFlexGrid2.RemoveItem(lngRow)
        End If
        if lngRow =  MSHFlexGrid2.Rows then exit do

    Loop

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 35692410
Thank you so much, this is working great
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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 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