david2005wang
New Member
- Joined
- Apr 8, 2022
- Messages
- 13
- Office Version
- 2021
- 2019
- 2013
- Platform
- Windows
Dear guys, I have codes as followings:
1. draw a userform with listbox1, and textbox1 which is used for input to search like-text in the listbox1 which shows the list of manufacturers in the sheets("manufacture").Range ("A1:A6"), the last row of the sheet , and 2 show the research result in the listbox1, but doens't work, it shows subscribe our of range in the line "brr(j, 1) = arr(i, 1)".
colud any expert to go through, check the code, and provide how to revise the code? thank you guys!
Private Sub UserForm_Initialize()
Dim sht As Worksheet, n As Long
Dim arr()
Set sht = Sheets("Manufacture")
n = sht.Range("A" & Rows.Count).End(xlUp).Row
arr = sht.Range("A1:A" & n)
ListBox1.List = arr
End Sub
Private Sub TextBox1_Change()
Dim sht As Worksheet, n As Long, arr(), C As Boolean
Set sht = Sheets("Manufacture")
n = sht.Range("A" & Rows.Count).End(xlUp).Row
arr = sht.Range("A1:A" & n)
Dim brr()
Dim i, j As Integer
For i = 1 To UBound(arr)
C = arr(i, 1) Like "*" & TextBox1.Text & "*"
If C Or i = 1 Then
j = j + 1
brr(j, 1) = arr(i, 1)
End If
Next
ListBox1.List = brr
End Sub
1. draw a userform with listbox1, and textbox1 which is used for input to search like-text in the listbox1 which shows the list of manufacturers in the sheets("manufacture").Range ("A1:A6"), the last row of the sheet , and 2 show the research result in the listbox1, but doens't work, it shows subscribe our of range in the line "brr(j, 1) = arr(i, 1)".
colud any expert to go through, check the code, and provide how to revise the code? thank you guys!
Private Sub UserForm_Initialize()
Dim sht As Worksheet, n As Long
Dim arr()
Set sht = Sheets("Manufacture")
n = sht.Range("A" & Rows.Count).End(xlUp).Row
arr = sht.Range("A1:A" & n)
ListBox1.List = arr
End Sub
Private Sub TextBox1_Change()
Dim sht As Worksheet, n As Long, arr(), C As Boolean
Set sht = Sheets("Manufacture")
n = sht.Range("A" & Rows.Count).End(xlUp).Row
arr = sht.Range("A1:A" & n)
Dim brr()
Dim i, j As Integer
For i = 1 To UBound(arr)
C = arr(i, 1) Like "*" & TextBox1.Text & "*"
If C Or i = 1 Then
j = j + 1
brr(j, 1) = arr(i, 1)
End If
Next
ListBox1.List = brr
End Sub