Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- 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
ListBox2 code i called it newuserform_initialize as i already have a userform_initialize
Commandbutton3 code in Userform2.
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