JumboCactuar
Well-known Member
- Joined
- Nov 16, 2016
- Messages
- 773
- Office Version
-
- 365
- Platform
-
- Windows
Hi,
i have this code
What it does is filter data on sheet 1 based on dropdown value (name)
Copies it to a user report sheet and the data is viewable from a userform
But im wanting on userform initialise for it to select the last entry, does anyone know how?
thanks
i have this code
Code:
Private Sub UserForm_Initialize()
Dim MyData As Range
Dim n As Integer
Dim r As Long
With ThisWorkbook.Sheets("Main").DropDowns("ComboBox1")
If .Value > 0 Then Call MacroX(.List(.Value))
End With
Label1.Caption = Sheets("Report").Range("C1")
Label2.Caption = Sheets("Report").Range("B17")
End Sub
Sub MacroX(sName As String)
Application.ScreenUpdating = False
With Sheets("Sheet1")
.Range("$A$1:$M$5000").AutoFilter Field:=3, Criteria1:=sName
.Columns("A:H").Copy Sheets("Report").Range("A21")
End With
Sheets("Sheet1").Range("$A$1:$M$5000").AutoFilter Field:=3
Sheets("Report").Range("A22:A5000").ClearFormats
Sheets("Report").Range("C22:H5000").ClearFormats
With Me.ListBox1
.RowSource = ""
.ColumnCount = 6
Set MyData = Worksheets("Report").Range("B21:G3000") 'Adjust the range accordingly
.List = MyData.Cells.Value
For r = .ListCount - 1 To 0 Step -1
If .List(r, 3) = "" Then
.RemoveItem r
End If
Next r
End With
For n = 0 To ListBox1.ListCount - 1
With ListBox1
.List(n, 0) = Format(.List(n, 0), "hh:mm")
End With
Next n
Application.ScreenUpdating = True
End Sub
What it does is filter data on sheet 1 based on dropdown value (name)
Copies it to a user report sheet and the data is viewable from a userform
But im wanting on userform initialise for it to select the last entry, does anyone know how?
thanks