auto refresh listbox2 in userform1

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi. good afternoon, hope you can help me please. I have a UserForm1 with a listbox, where the values in the listbox2 come from sheets 'Outages data'. i then have another userform2, where data is entered and when commandbutton3 is pressed the data goes into sheets 'Outages data', and should populate the data in userform1.listbox2. This doesnt happen though until i exit the userforms and re open them, i have tried the code below to auto refresh to save me closing down the userforms but it doesnt work i hope you can help me please.

Module
VBA Code:
Option Explicit
Private t
Sub ShowForm()
UserForm1.Show
End Sub
Sub StartThem()
    UpdateListBoxes
    t = DateAdd("s", 5, Time) ' Change the 5 to 60 to refresh every 60 seconds.
    Application.OnTime t, "StartThem"
End Sub
Sub StopThem()
    Application.OnTime t, "StartThem", , False
    Unload UserForm1
End Sub
Sub UpdateListBoxes()
    With Worksheets("Outages data").Cells(1).CurrentRegion
        UserForm1.ListBox2.RowSource = .Address
    End With
End Sub

ListBox2 code i called it newuserform_initialize as i already have a userform_initialize

Code:
Private Sub ListBox2_Click()
End Sub

Private Sub NewUserForm_Initialize()
StartThem
End Sub

Commandbutton3 code in Userform2.

Code:
Option Explicit


Private Sub CommandButton3_Click()
    If TextBox3.Value = "" Then
        MsgBox "Please enter 'Notes'"
        Exit Sub
    Else

    End If
    
Dim emptyRow As Long

With ThisWorkbook.Sheets("Outages data")
   emptyRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
 
   .Cells(emptyRow, 1).Value = IIf(ComboBox1.Value = "", "NA", ComboBox1.Value)
   .Cells(emptyRow, 2).Value = IIf(TextBox1.Value = "", "NA", TextBox1.Value)
   .Cells(emptyRow, 3).Value = IIf(TextBox2.Value = "", "NA", TextBox2.Value)
   .Cells(emptyRow, 4).Value = IIf(ComboBox2.Value = "", "NA", ComboBox2.Value)
.Cells(emptyRow, 5).Value = IIf(TextBox3.Value = "", "NA", TextBox3.Value)

End With

 
 
Unload Me



    StopThem
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hope you can help me please, be much appreciated thank you
 
Upvote 0
hi good morning, i have tried to do it simpler now thant hte above code where i have put a command button in Userform1 to refresh the Lsitbox but this still does not load, hope you can help please?
VBA Code:
Private Sub CommandButton10_Click()
Dim strRowSource As String
Dim emptyRow As Long

With ThisWorkbook.Sheets("Outages data")
   emptyRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
    With UserForm1.ListBox2
        strRowSource = .RowSource
        .RowSource = vbNullString
        'Set back so it updates, use a new RowSource
        .RowSource = strRowSource
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

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