Ok, this is giving me a headache.
I thought it wouldn't be too hard to make a small userform with some code that would simply hide/unhide rows based on the selection of those rows in a listbox.
Basically I have a table with labels in column C. i want to be able to bring up a simple userform that autopopulates the labels... and has checkboxes so i can toggle which of these rows is visible (multiple selections possible). Currently I've been able to populate the listbox... and, on initialize, populate each item in the list with checks if they are already visible, or no checks if they are hidden... the problem is, when making any change.... it makes the first change (making the first item in the list either (correctly) visible or hidden... but then for some reason, the whole rest of the list becomes unchecked!?
I've worked out it has come down to the following line of code (i think):
Rows(r + t).Hidden = False
... because as soon as I comment it... then i can get a feed of the whole list that correctly identifies whether the checkbox is selected or not for each item.
Here is pretty much all the code from the "setvisiblestats userform"... it's pretty simple really... i left the debug lines in there so you can see that I'm not crazy.
Please help!
I thought it wouldn't be too hard to make a small userform with some code that would simply hide/unhide rows based on the selection of those rows in a listbox.
Basically I have a table with labels in column C. i want to be able to bring up a simple userform that autopopulates the labels... and has checkboxes so i can toggle which of these rows is visible (multiple selections possible). Currently I've been able to populate the listbox... and, on initialize, populate each item in the list with checks if they are already visible, or no checks if they are hidden... the problem is, when making any change.... it makes the first change (making the first item in the list either (correctly) visible or hidden... but then for some reason, the whole rest of the list becomes unchecked!?
I've worked out it has come down to the following line of code (i think):
Rows(r + t).Hidden = False
... because as soon as I comment it... then i can get a feed of the whole list that correctly identifies whether the checkbox is selected or not for each item.
Here is pretty much all the code from the "setvisiblestats userform"... it's pretty simple really... i left the debug lines in there so you can see that I'm not crazy.
Code:
Private Sub UserForm_Initialize()
Dim r As Integer
Dim t As Integer
t = Application.WorksheetFunction.Match(lbStats.List(0), Range("C:C"), 0)
For r = 0 To lbStats.ListCount - 1
If Rows(r + t).Hidden = True Then
lbStats.Selected(r) = False
Else
lbStats.Selected(r) = True
End If
Next r
End Sub
Private Sub cmdSUBMIT_Click()
Application.ScreenUpdating = False
ThisWorkbook.Worksheets("main").Activate
Dim r As Integer
Dim t As Integer
'aligns the index with the first value of the list
t = Application.WorksheetFunction.Match(lbStats.List(0), Range("C:C"), 0)
For r = 0 To lbStats.ListCount - 1
[I] Debug.Print "BEFORE IF row" & r & lbStats.Selected(r)[/I]
If lbStats.Selected(r) = True Then
[COLOR=#0000ff][/COLOR][I]Debug.Print "UNHIDE before action - row" & r & lbStats.Selected(r) & " next is " & lbStats.Selected(r + 1)[/I][COLOR=#0000ff][I] 'this shows the checkbox status of the current and next item[/I][/COLOR]
[B][COLOR=#ff0000]Rows(r + t).Hidden = False [/COLOR][/B] [COLOR=#0000ff]' THIS IS THE LINE THAT IS ANNOYING MEEEEEE!!!!!!!![/COLOR]
[COLOR=#0000ff][/COLOR][I] Debug.Print "UNHIDE after action - row" & r & lbStats.Selected(r) & " next is " & lbStats.Selected(r + 1)[/I][COLOR=#0000ff][I] 'as above, but AFTER the previous action[/I][/COLOR]
Else
Rows(r + t).Hidden = True
[I] Debug.Print "HIDE row" & r; lbStats.Selected(r) & " next is " & lbStats.Selected(r + 1)[/I]
End If
Next r
resetForm
End Sub
Please help!