ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,932
- Office Version
- 2007
- Platform
- Windows
Hi,
I am using the code below.
As you can see its USERFORM_INITIALIZE format.
Obviously when i first open the worksheet & select the userform i see the correct valuer in the TextBox.
If i then add a new row to the worksheet & open the userform again the result is still the same in the TextBox.
If i open another worksheet then come back to open this worksheet the userform then shows the correct value in the TextBox
I know its because im using Initalize but what should i be using so its always updating itself to show the correct value in the TextBox
How do i Initialize the code witrhout having to close & open worksheet
I am using the code below.
As you can see its USERFORM_INITIALIZE format.
Obviously when i first open the worksheet & select the userform i see the correct valuer in the TextBox.
If i then add a new row to the worksheet & open the userform again the result is still the same in the TextBox.
If i open another worksheet then come back to open this worksheet the userform then shows the correct value in the TextBox
I know its because im using Initalize but what should i be using so its always updating itself to show the correct value in the TextBox
How do i Initialize the code witrhout having to close & open worksheet
Rich (BB code):
Private Sub UserForm_Initialize()
With ThisWorkbook.Worksheets("DATABASE")
Dim data As Variant
data = .Range("J6:K" & .Cells(.Rows.Count, "J").End(xlUp).Row).Value
End With
ReDim arr(0 To 1, 0 To UBound(data) - 1) As String
Dim itm As String
Dim cnt As Long
Dim i As Long
cnt = 0
For i = LBound(data) To UBound(data)
itm = data(i, 1)
If itm Like "[A-Za-z]###" Then
arr(0, cnt) = itm
arr(1, cnt) = data(i, 2)
cnt = cnt + 1
End If
Next i
If cnt > 1 Then
ReDim Preserve arr(0 To 1, 0 To cnt - 1)
Sort2DArray arr()
Me.ListBox1.List = Application.Transpose(arr())
ElseIf cnt > 0 Then
Me.ListBox1.Column = arr()
End If
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("DATABASE")
ws.Range("AB6").CurrentRegion.ClearContents
With Me.ListBox1
ws.Range("AB6").Resize(.ListCount, .ColumnCount).Value = .List
End With
With ThisWorkbook.Worksheets("DATABASE")
TextBox1 = Range("A1")
End With
End Sub