Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,064
- Office Version
- 2016
- Platform
- Windows
I have a userform with a multipage, on each page I have a listbox, the data for the listbox come from each sheet. The listboxes flickers when the data is updates in them. If I place a wait time in my FOR LOOP OR Sheet Change Event then the flickering goes away. The only problem is that it slows down the code a lot. I was trying to set it to millseconds, like half a second, but could not get it to work.
Please see question at the bottom of this thread. Thanks
I have also posted on Stackoverflow Here
For Loop
Or I can place the wait time in the Sheet Change Event
Sheet Change Event
A One second delay slows the code down too much. I was advised on Stackover Flow to do the Sheet Change Event As an "Intersect". I have Google it, but don't know how to change my code to test if that will work, I have put an updated code on Stackoverflow, but not sure if it is correct as it did not get rid of the problem.
This was another code that I was using, but it would not update when the result would go into the sheet. It ONLY updated if I closed the form and reopened it.
Q1) Is there a way to refresh the above code every few seconds, with a loop and application wait time?
So as long as data is going ito sheet2 it loops and refreshers one of the above codes, ensuring the CURRENT sheet data show in the listbox. This way I DO NOT have to add a wait time to my code FOR Loop to slow it down or the sheetchange event, just a refresh. The data will go in as normal and will refresh the listbox with the current data every few seconds and then end the refresh waittime loop when the data input has stopped in sheet2.
Hopefull this will stop the flickering, as the list box is updated every few seconds.
Thanks
Please see question at the bottom of this thread. Thanks
I have also posted on Stackoverflow Here
For Loop
VBA Code:
Do
For Each li In HTMLdoc.getElementsByTagName("li")
If li.getAttribute("class") = "b_algo" Then
Set link = li.getElementsByTagName("a")(0)
.Cells(i, 1).Value = link.getAttribute("href")
'###### TIME DELAY SET TO 1 SECOND ######
Application.Wait (Now + TimeValue("0:00:01"))
'Application.Wait (Now + 0.000001) 'FOR MILLSECONDS
i = i + 1
End If
Next li
Or I can place the wait time in the Sheet Change Event
Sheet Change Event
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With ExcelForm.UrlsListBox1
.ColumnCount = 1
.ColumnWidths = "600"
'###### TIME DELAY SET TO 1 SECOND ######
Application.Wait (Now + TimeValue("0:00:01"))
'Application.Wait (Now + 0.000001) 'FOR MILLSECONDS
.RowSource = "'" & Sheet2.Name & "'!$A$1:$b$" & Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).row
End With
End Sub
A One second delay slows the code down too much. I was advised on Stackover Flow to do the Sheet Change Event As an "Intersect". I have Google it, but don't know how to change my code to test if that will work, I have put an updated code on Stackoverflow, but not sure if it is correct as it did not get rid of the problem.
This was another code that I was using, but it would not update when the result would go into the sheet. It ONLY updated if I closed the form and reopened it.
VBA Code:
Private Sub UserForm_Initialize()
With Me.MultiPage2.Pages(1).ListBox3
.ColumnCount = 1
.ColumnWidths = "600"
.RowSource = "'" & Sheet2.Name & "'!$A$1:$B$" & Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Row
End With
End Sub
Q1) Is there a way to refresh the above code every few seconds, with a loop and application wait time?
So as long as data is going ito sheet2 it loops and refreshers one of the above codes, ensuring the CURRENT sheet data show in the listbox. This way I DO NOT have to add a wait time to my code FOR Loop to slow it down or the sheetchange event, just a refresh. The data will go in as normal and will refresh the listbox with the current data every few seconds and then end the refresh waittime loop when the data input has stopped in sheet2.
Hopefull this will stop the flickering, as the list box is updated every few seconds.
Thanks