Hi All,
I am having a bit of an odd issue. When I click the Red X box at the top of my user form (which only contains 1 combobox). It clears all of the items out of my Combo Box the next time I trigger the form. When I select a valid value it autocloses fine and my code hides the form and uses the data require fine. Next time I select it works fine all the items are still in my combo box, but when I quit via (red X - Sorry can't thing of the right term for this) and re-open the form all the data is gone. The code is in 3 parts so I have included it all.
The form is triggered(shown) when I click on a cell. That all seems to work fine. So the user would click on the cell. Select a value from the drop down or exit Using form close(Red X). The user can then re-select this whenever they like. it is supposed to work like an Autofilter because I cannot use the autofilter as all items on this page are locked and protected. So I created a form to in effect emulate it.
Code Part 1 - Creating the Combo Box data (adding items) - This is called only once before control is passed to a new sheet
If FM_FilterForm.ComboBox1.ListCount <> 0 Then
For x = 1 To FM_FilterForm.ComboBox1.ListCount
FM_FilterForm.ComboBox1.RemoveItem 0
Next x
End If
FM_FilterForm.ComboBox1.AddItem "All"
rw = Range("Site_Data").Row
col = Range("Site_Data").Column
While Sheets("Formula Page").Cells(rw, col) <> ""
If Sheets("Formula Page").Cells(rw, col + 3) = FM_Required Then
FM_FilterForm.ComboBox1.AddItem Sheets("Formula Page").Cells(rw, col).Text
End If
rw = rw + 1
Wend
The second bit of code is the code that triggers the loading of the user form when a cell is clicked on (I removed the DIM's for size but all variables have been dimensioned
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Clicked = Target.Address(False, False, xlA1, False, "A1")
If Clicked = "C4" And Range("A2") = "Edit" Then
WasItCancelled = True
FM_FilterForm.Left = Target.Left
FM_FilterForm.Top = Target.Top
FM_FilterForm.Show
If WasItCancelled = True Then
' FM_FilterForm.Hide 'disabled this as I thought that might remove items but no change
Exit Sub
Else
' Does code that applies various filters to sheet data (No futher operations on the form
End Sub
And Finally the code that is actually associated with the form and/or Combo Box
Private Sub ComboBox1_Click()
WasItCancelled = False
ActiveSheet.Unprotect Password:=Sheets("Formula Page").Range("R1")
Range("C2") = ComboBox1.Value
ActiveSheet.Protect Password:=Sheets("Formula Page").Range("R1"), DrawingObjects:=True, Contents:=True, Scenarios:=True
FM_FilterForm.Hide
End Sub
Private Sub UserForm_Activate()
ComboBox1.Object.Value = "" ' So no value is selected from last time
End Sub
Private Sub UserForm_Terminate()
WasItCancelled = True
Sheets("Original Information").Range("A3").Select 'So I can re-select the cell immediately as focus is changed
End Sub
I just cannot understand why this is removing the items from the list. The combo box displays but there are no items within it?
Please help before I become totally bald!!
Thanks
Bookmarks