ListBox Selection Associated with Visible Cells in a SpreadSheet

MDC Controls

New Member
Joined
Jun 7, 2013
Messages
1
Many thanks to all at Mr. Excel for all the help I have already received searching for tips and tricks. I am a new registered user and this is my first post. I could not figure this one out.

I have a spreadsheet with a list of Event Documents and their file paths. I have some code that lists the documents in a form Listbox. When a listbox item is selected, I have other code that identifies the row number in the spreadsheet corresponding to the Listbox ListIndex, counts the appropriate number of rows down the spreadsheet to identify the file path in the adjacent column to display the contents in an adjacent Textbox.
This works great until I filter the spreadsheet. I am successful at listing the filtered cells into the Listbox, but when I select a document on the form’s Listbox, it counts down the invisible cells as well as the visible cells, but I only want it to count the visible cells.
Below is the code:

Code:
Private Sub ListBox_ER_List_Click()
 
 
       Dim sTxt$, sText$, sPath$, sLIV$
             
' This identifies the row number in the spreadsheet, _
   corresponding to the Listbox slection:
        sLIV = ListBox_ER_List.ListIndex + 2
      
       
' This identifies the path. listed in the F column of the spreadsheet _
   it works great if the spreasheet is not filtered
        sPath = Worksheets("Event_Directory").Range("f" & sLIV).Value
 
' This is an example of various attempts to do the same as the above, _
    but with the visible cells only:
        sPath = Worksheets("Event_Directory").SpecialCells(xlCellTypeVisible).Range("f" & sLIV).Value
'the above creates RunTime Error 438 - Object doesn't support this property or method
       
'This is the rest of the code that follows the path (sPath) and then displays _
 the contents of the document in an adjacent Textbox whitout problems
        If Dir(sPath) = "" Then
        MsgBox "File was not found."
        Exit Sub
        End If
       
        Close
        Open sPath For Input As #1
        Do Until EOF(1)
        Line Input #1, sTxt
        sText = sText & sTxt & vbLf
        Loop
        Close
       
        sText = Left(sText, Len(sText) - 1)
        Me.TextBox_Txt.Text = sText
 
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,215,381
Messages
6,124,615
Members
449,175
Latest member
Anniewonder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top