VBA help I need to combine two codes

Quan71

New Member
Joined
Dec 10, 2022
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
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

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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: How to combine two codes - OzGrid Free Excel/VBA Help Forum
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

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