ListBox on a form with vbModeless

Skippy

Board Regular
Joined
Mar 3, 2002
Messages
194
I am a bit cofused about something. I have a ListBox on a form that I fill using RowSource. When I set UserForm1.Show with vbModeless, the data in the listbox starts disappearing when I scroll up and down the list. Setting the form to vbModal doesn't cause this problem. Any ideas why (or how I can prevent this problem using vbModeless)?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I'm reading from a worksheet range (also Excel 2000).
Code:
    Set rng = Sheets("Raw data Folio (2)").Range("CA2:CI" & Range("CA65536") _
        .End(xlUp).Row)
    With frmMain.lstSummary
        .ColumnCount = 9
        .RowSource = rng.Address
        cw = ""
        For c = 1 To 9
            cw = cw & rng.Columns(c).Width & ";"
        Next c
        .ColumnWidths = cw
        .ListIndex = 0
    End With
            
    With frmMain
        .Show vbModal
        .lblRecords = "No. of records: " & .lstSummary.ListCount
    End With
 
Upvote 0
You probably need to include a sheet reference, otherwise the ActiveSheet will be used:

Code:
Private Sub UserForm_Initialize()
    With Sheets("Raw data Folio (2)")
        Set rng = .Range("CA2:CI" & .Range("CA65536").End(xlUp).Row)
    End With
    With frmMain.lstSummary
        .ColumnCount = 9
        .RowSource = "'Raw data Folio (2)'!" & rng.Address
        cw = ""
        For c = 1 To 9
            cw = cw & rng.Columns(c).Width & ";"
        Next c
        .ColumnWidths = cw
        .ListIndex = 0
    End With
End Sub

The same goes for the second part of your Range statement, so I put it in a With ... End With construct.
 
Upvote 0
Thanks Andrew. This was only a snippet of my code. What wasn't showing was that I had set the sheet to be active. So, while good that you pointed out a potential issue with my code, it is not related to my original problem.
 
Upvote 0
Skippy said:
Thanks Andrew. This was only a snippet of my code. What wasn't showing was that I had set the sheet to be active. So, while good that you pointed out a potential issue with my code, it is not related to my original problem.

Well, I still can't reproduce your original problem, sorry.
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

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