Hi experts I need to combine two codes
But I won't use it, it will generate an error
Ask the experts to help with this problem. Attach the sample sheet Sample Sheet
But I won't use it, it will generate an error
Ask the experts to help with this problem. Attach the sample sheet Sample Sheet
VBA Code:
Private Sub CommandButton3_Click()
Dim arr, brr
Dim M, n As Integer
Dim s As String
n = Sheets("Sheet1").[D65536].End(xlUp).Row
arr = Sheets("Sheet1").Range("C1:N" & n)
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
For i = 1 To UBound(arr, 2)
brr(1, i) = arr(1, i)
Next
M = 1
For i = 2 To UBound(arr)
If arr(i, 2) Like "*" & UserForm1.TextBox6.Text & "*" And arr(i, 6) Like "*" & UserForm1.TextBox5.Text & "*" Then
M = M + 1
For j = 1 To UBound(arr, 2)
brr(M, j) = arr(i, j)
Next
End If
Next
ReDim arr(1 To M, 1 To UBound(brr, 2))
For i = 1 To M
For j = 1 To UBound(brr, 2)
arr(i, j) = brr(i, j)
Next
Next
UserForm1.ListBox3.List = arr
End Sub
Private Sub CommandButton3_Click()
Dim arr, brr
Dim M, n As Integer
Dim s As String
Dim dt1, dt2 As Date
dt1 = DateSerial(ComboBox2.Value, ComboBox3.Value, ComboBox4.Value)
dt2 = DateSerial(ComboBox5.Value, ComboBox6.Value, ComboBox7.Value)
n = Sheets("Sheet1").[D65536].End(xlUp).Row
arr = Sheets("Sheet1").Range("C1:N" & n)
ReDim brr(1 To UBound(arr, 2), 1 To 1)
For i = 1 To UBound(arr, 2)
brr(i, 1) = arr(1, i)
Next
M = 1
For i = 2 To UBound(arr)
If arr(i, 1) >= dt1 And arr(i, 1) <= dt2 Then
M = M + 1
ReDim Preserve brr(1 To UBound(arr, 2), 1 To M)
For j = 1 To UBound(arr, 2)
brr(j, M) = arr(i, j)
Next
End If
Next
UserForm2.ListBox3.List = Application.Transpose(brr)
End Sub
Private Sub UserForm_Activate()
n = Sheets("sheet1").[D65536].End(xlUp).Row
arr = Sheets("sheet1").Range("C1:N" & n)
UserForm2.ListBox3.ColumnCount = 20
UserForm2.ListBox3.ColumnWidths = 60 & ";" & 50 & ";" & 40 & ";" & 40 & ";" _
& 60 & ";" & 80 & ";" & 50 & ";" & 50 & ";" & 50 & ";" & 50
UserForm2.ListBox3.List = arr
ComboBox2.List = Array(2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032)
ComboBox5.List = Array(2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032)
ComboBox3.List = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
ComboBox6.List = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
ComboBox4.List = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31)
ComboBox7.List = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31)
End Sub
Private Sub UserForm_Activate()
n = Sheets("sheet1").[D65536].End(xlUp).Row
arr = Sheets("sheet1").Range("C1:N" & n)
UserForm1.ListBox3.ColumnCount = 10
UserForm1.ListBox3.ColumnWidths = 60 & ";" & 50 & ";" & 40 & ";" & 40 & ";" _
& 60 & ";" & 80 & ";" & 50 & ";" & 50 & ";" & 50 & ";" & 50
UserForm1.ListBox3.List = arr
End Sub