Hi.
i have error, when use loop (filter criteria) in ListView.
look step-by-step in my file tab("Image_Error)
Hi.
i have error, when use loop (filter criteria) in ListView.
look step-by-step in my file tab("Image_Error)
"No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.
If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.
Not sure what is going on with your code, you are selecting A4 and then xldown, but there is nothing below A4. What is supposed to happen?
Last edited by davesexcel; 12-21-2013 at 06:00 AM.
Hi
I got watching a tutorialI am quite surprised with your quality of code, when do you ever select a range in a userform?
Hi, marreco,
I doubt it´s good practise to fill a ComboBox with any available value from a list and then afterwards work with a couple of loops to make the items unique. I´d expected to work with CountIf here and only add items if they appear for the first time.
Whenever you make any choice in the first ComboBox the number of filled columns reduces from 9 to 5 so you should try and only convert that in the code:![]()
'Loop das colunas For j = 1 To Me.ListView2.ListSubItems.Count - 1 Cells(i + 3, j + 1) = ListView2.ListItems(i).ListSubItems(j).Text Next j
I find it really difficult to have no information about what you want to do but to have a look at a workbook with comments in a foreign language, controls in a foreign language and not get the idea of what you are up to as the code itself interestingly brings up questions: why is there more than one entry if I choose 1 in the forst combobox? There should only be one name listed, not three - how does that fit in?![]()
'Loop das colunas For j = 1 To 4 Cells(i + 3, j + 1) = ListView2.ListItems(i).ListSubItems(j).Text Next j
Ciao,![]()
Private Sub CommandButton2_Click() Dim i As Long, j As Long With Sheets("Relatorio") If .Range("A4") = "" Then 'nada faz Else .Range("A4:I" & .Range("A" & Rows.Count).End(xlUp).Row).ClearContents End If 'Loop das linhas For i = 1 To Me.ListView2.ListItems.Count .Cells(i + 3, 1) = ListView2.ListItems(i).Text 'Loop das colunas For j = 1 To 4 .Cells(i + 3, j + 1) = ListView2.ListItems(i).ListSubItems(j).Text Next j Next i End With End Sub
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
Hi, holger
What a wonderful solution!
Thank you very much!
Hi there,
Thank you for the private message you sent me.
The problem lies in the highlighted line in the following routine:
![]()
Private Sub CommandButton2_Click() Application.ScreenUpdating = True Sheets("Relatorio").Select If Range("A4") = "" Then 'nada faz Else Range("A4").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.ClearContents Range("A3").Select End If Range("A4").Select Dim i As Integer, j As Integer ' Loop das linhas For i = 1 To ListView2.ListItems.Count Cells(i + 3, 1) = ListView2.ListItems(i).Text ' Loop das colunas For j = 1 To ListView2.ColumnHeaders.Count - 1 Cells(i + 3, j + 1) = ListView2.ListItems(i).ListSubItems(j).Text Next j Next i End Sub
When the form is intitialised the number of data items the ListView contains is indeed equal to the number of Column Headers (i.e. nine), but when the above routine is executed the ListView contains only five items - this is the reason for the "Index out of bounds" error message.
To correct this error you should replace the above highlighted statement with the following:
![]()
For j = 1 To ListView2.ListItems(i).ListSubItems.Count
Take a look at the attached workbook and see if it does what you want. I've restructured a lot of your code so that the UserForm is now much more loosely coupled to worksheets than it was before. In general a UserForm should "know" as little as possible about the worksheets/workbook with which it is being used - reducing the coupling to the absolute minimum greatly increases the possibility of being able to use the UserForm in other applications.
Hope the above helps - please let me know how you get on with it.
Regards,
Greg M
Hi Greg M
Very good, i like it!!
thank you very much!!!!!!!!!!!!!!!![]()
Hi again,
Many thanks for your very prompt feedback - I'm very pleased that I was able to help.
Best regards,
Greg M
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks