Filter Data In User Form
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter Data In User Form
I would be happy If I get any help to make it logical If what I had assumed is inlogical
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter Data In User Form
Yes I did try & I'm still out of luck. If I'm able to do I wouldn't have come to a forum.
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Filter Data In User Form
Could you post the most recent version of your workbook?
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter Data In User Form
Oh Hans!
is changed to
there's no improvement
and if the whole code is changed to A4 I cant get what I had asked.
Code: Select all
a = Sheets("Invoice").Range("A4").CurrentRegion.Offset(1, 1).Resize(, 1)
Code: Select all
a = Sheets("Invoice").Range("A3").CurrentRegion.Offset(1, 1).Resize(, 1)
and if the whole code is changed to A4 I cant get what I had asked.
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter Data In User Form
Hans, as per your replies and suggestion I have changed my mind to leave the code as it is; meaning to use a combo box and a list box to filter the data from the sheet “Ordersâ€
But since my data starts from the row 4 and the column that I want to assign is column 2 which contains the serial number neither the original code nor your version of the code does work with my combo box.
Here is how I changed the list box in your version of the code.
Instead of
I tried by using
But it didn’t work.
And as in the original code I tried by using
The changes that you have made to the original code is using the line
Instead of the line
Also the following
Is changed as
How could I make my combo box to work by having the data to start from row 4 and the column that I want to assign is column 2 of the orders sheet?
I hope this is within the limit and any assistance if provided will be kindly appreciated.
In Short: to make the combo box work instead of the list box in the workbook that you had uploaded
But since my data starts from the row 4 and the column that I want to assign is column 2 which contains the serial number neither the original code nor your version of the code does work with my combo box.
Here is how I changed the list box in your version of the code.
Instead of
Code: Select all
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim w(), i As Long, c As Long, n As Long
ReDim w(1 To UBound(Data, 1), 1 To UBound(Data, 2))
For i = 1 To UBound(Data, 1)
If Data(i, 2) = Me.ListBox2.Value Then
n = n + 1
For c = 1 To UBound(Data, 2)
w(n, c) = Data(i, c)
Next c
End If
Next i
If n > 0 Then
With Sheets("Orders").Range("M1") 'adjust the range to paste the filtered data
.Resize(, UBound(Data, 2)).Value = Sheets("Orders").Range("A4"). _
Resize(, UBound(Data, 2)).Value
.Offset(1).Resize(n, UBound(Data, 2)).Value = w
.Offset(1).Resize(n, UBound(Data, 2)).Name = "SourceRng"
End With
With Me.ListBox1
.ColumnCount = UBound(Data, 2)
.ColumnHeads = True
.RowSource = Range("SourceRng").Address(External:=True)
End With
End If
End Sub
Code: Select all
Private Sub ComboBox1_Change()
Dim w(), i As Long, c As Long, n As Long
ReDim w(1 To UBound(Data, 1), 1 To UBound(Data, 2))
For i = 1 To UBound(Data, 1)
If Data(i, 1) = Me.ComboBox1.Value Then
n = n + 1: For c = 1 To UBound(Data, 2): w(n, c) = Data(i, c): Next
End If
Next
'# 1
'If n > 0 Then
' With Me.ListBox1
' .Clear
' .ColumnCount = UBound(Data, 2)
' .List = w
' End With
'End If
'if you need column headings as well then use # 2
'#2
If n > 0 Then
With Sheets("Orders").Range("M1") 'adjust the range to paste the filtered data
.Resize(, UBound(Data, 2)).Value = Sheets("Orders").Range("A4"). _
Resize(, UBound(Data, 2)).Value
.Offset(1).Resize(n, UBound(Data, 2)).Value = w
.Offset(1).Resize(n, UBound(Data, 2)).Name = "SourceRng"
End With
With Me.ListBox1
.ColumnCount = UBound(Data, 2)
.ColumnHeads = True
.RowSource = Range("SourceRng").Address(external:=True)
End With
End If
End Sub
And as in the original code I tried by using
The changes that you have made to the original code is using the line
Code: Select all
If Data(i, 2) = Me.ListBox2.Value Then
Code: Select all
If Data(i, 1) = Me.ComboBox1.Value Then
Code: Select all
n = n + 1: For c = 1 To UBound(Data, 2): w(n, c) = Data(i, c): Next
End If
Next
Code: Select all
n = n + 1
For c = 1 To UBound(Data, 2)
w(n, c) = Data(i, c)
Next c
End If
Next i
I hope this is within the limit and any assistance if provided will be kindly appreciated.
In Short: to make the combo box work instead of the list box in the workbook that you had uploaded
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Filter Data In User Form
You're still asking us to rewrite the code for you.
I gave you a working version in Post=17762 on the first page of this thread. If you're not able to modify it to suit your needs, I suggest that you stick with that version.
I gave you a working version in Post=17762 on the first page of this thread. If you're not able to modify it to suit your needs, I suggest that you stick with that version.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter Data In User Form
Thanks for the reply. By the way just want to let you know that I've never asked to rewrite the code.
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 12618
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Filter Data In User Form
Adam,
You seem to have great difficulty taking example code and making changes to it that people suggest.
I think you may find it very useful to take a basic course in VBA programming, to make sure that you have all the basic concepts and help you to benefit from the advice that people give you.
You seem to have great difficulty taking example code and making changes to it that people suggest.
I think you may find it very useful to take a basic course in VBA programming, to make sure that you have all the basic concepts and help you to benefit from the advice that people give you.
StuartR
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter Data In User Form
Finally I have solved the problem.
But there’s a minor change that I couldn’t over come.
I have added an lsitbox1 one to the user form, which when double clicked fills the text boxes and the combo boxes assigned. When the combo box “Serial No†is filled by double clicking the list box 1 I get the message “Could not get column property. Invalid property array indexâ€
But If I select a number from the combo box the list box 2 gets filled.
I would be happy if I’m told what the reason behind this is.
I've attached the workbook for your reference.
Any help would be kindly appreciated.
By the way, thanks Stuart for letting me know that I have great difficulty taking example code and making changes to it that people suggest.
Also thanks for your opinion that I may find it very useful to take a basic course in VBA programming, to make sure that I have all the basic concepts and help me to benefit from the advice that people give me.
But there’s a minor change that I couldn’t over come.
I have added an lsitbox1 one to the user form, which when double clicked fills the text boxes and the combo boxes assigned. When the combo box “Serial No†is filled by double clicking the list box 1 I get the message “Could not get column property. Invalid property array indexâ€
But If I select a number from the combo box the list box 2 gets filled.
I would be happy if I’m told what the reason behind this is.
I've attached the workbook for your reference.
Any help would be kindly appreciated.
By the way, thanks Stuart for letting me know that I have great difficulty taking example code and making changes to it that people suggest.
Also thanks for your opinion that I may find it very useful to take a basic course in VBA programming, to make sure that I have all the basic concepts and help me to benefit from the advice that people give me.
Last edited by adam on 04 Jun 2010, 19:08, edited 1 time in total.
Best Regards,
Adam
Adam
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Filter Data In User Form
The ListBox1_DblClick event procedure changes cboSerialNo, but this causes the event procedure cboSerialNo_Change to run. This, in turn, writes data to the workbook. Because this might influence the row source of ListBox1, the selection in ListBox1 is canceled.
To get around this, you must place the line
Me.cboSerialNo = Me.ListBox1.Column(0)
at the end of ListBox1_DblClick instead of at the beginning.
To get around this, you must place the line
Me.cboSerialNo = Me.ListBox1.Column(0)
at the end of ListBox1_DblClick instead of at the beginning.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter Data In User Form
Thanks for the help Hans. I do really appreciate that.
Best Regards,
Adam
Adam