Hi Scott,
I had time to implement the changes I mentioned in the previous post. My goal is to make you comfortable with your file. Anything that I did is negotiable, if you don't like the say I did something.See the attached copy of your file which implements the following:
a. Inserted new row 2 in Sheet 'Data'. It is currently VISIBLE, so you can see what I did.
b. Implemented code to seed the UserForm ComboBoxes with some Categories omitted. The omitted categories are NOT BLANK in row 2.
c. Implemented code to remove a Category from all ComboBox lists when the category is used by any ComboBox. If there was a VALUE in the ComboBox, that VALUE is placed in restored in all ComboBox lists.
The changes above were made to the UserForm module (changes in red), and the addition of module 'ModUserFormTransactions'.
UserForm 'Transactions' modified routines:
Private Sub BnResetAllocate_Click()
'Disable UserForm Events
bGblTransactionsInhibitUserFormEvents = True
Me.TbDeposit.Value = "0.00"
Me.TbSpend.Value = "0.00"
Me.TbSplit1.Value = "0.00"
Me.TbSplit2.Value = "0.00"
Me.TbSplit3.Value = "0.00"
Me.TbSplit4.Value = "0.00"
Me.TbSplit5.Value = "0.00"
Me.TbSplit6.Value = "0.00"
Me.TbPosted.Value = "0.00"
Me.TbUnposted.Value = "0.00"
Me.CStore.Value = ""
Me.CbAllocate1.Clear
Me.CbAllocate2.Clear
Me.CbAllocate2.Visible = False
Me.Lb2.Visible = False
Me.TbSplit2.Visible = False
Me.CbAllocate3.Clear
Me.CbAllocate3.Visible = False
Me.Lb3.Visible = False
Me.TbSplit3.Visible = False
Me.CbAllocate4.Clear
Me.CbAllocate4.Visible = False
Me.Lb4.Visible = False
Me.TbSplit4.Visible = False
Me.CbAllocate5.Clear
Me.CbAllocate5.Visible = False
Me.Lb5.Visible = False
Me.TbSplit5.Visible = False
Me.CbAllocate6.Clear
Me.CbAllocate6.Visible = False
Me.Lb6.Visible = False
Me.TbSplit6.Visible = False
Me.LBPosted.Clear
Call PopulateUserFormTransactionsComboBoxes
Me.CbAllocate1.Value = ""
'Enable UserForm Events
bGblTransactionsInhibitUserFormEvents = False
End Sub
Private Sub CbAllocate1_Change()
If bGblTransactionsInhibitUserFormEvents = False Then
Me.CbAllocate2.Visible = True
Me.TbSplit2.Visible = True
Me.Lb2.Visible = True
Call ProcessUserFormTransactionsComboBoxChangeEvents
End If
End Sub
Private Sub CbAllocate2_Change()
If bGblTransactionsInhibitUserFormEvents = False Then
Me.CbAllocate3.Visible = True
Me.TbSplit3.Visible = True
Me.Lb3.Visible = True
Call ProcessUserFormTransactionsComboBoxChangeEvents
End If
End Sub
Private Sub CbAllocate3_Change()
If bGblTransactionsInhibitUserFormEvents = False Then
Me.CbAllocate4.Visible = True
Me.TbSplit4.Visible = True
Me.Lb4.Visible = True
Call ProcessUserFormTransactionsComboBoxChangeEvents
End If
End Sub
Private Sub CbAllocate4_Change()
If bGblTransactionsInhibitUserFormEvents = False Then
Me.CbAllocate5.Visible = True
Me.TbSplit5.Visible = True
Me.Lb5.Visible = True
Call ProcessUserFormTransactionsComboBoxChangeEvents
End If
End Sub
Private Sub CbAllocate5_Change()
If bGblTransactionsInhibitUserFormEvents = False Then
Me.CbAllocate6.Visible = True
Me.TbSplit6.Visible = True
Me.Lb6.Visible = True
Call ProcessUserFormTransactionsComboBoxChangeEvents
End If
End Sub
Private Sub CbAllocate6_Change()
If bGblTransactionsInhibitUserFormEvents = False Then
Call ProcessUserFormTransactionsComboBoxChangeEvents
End If
End Sub
Private Sub UserForm_Initialize()
Me.TbDeposit.Value = "0.00"
Me.TbSpend.Value = "0.00"
Me.TbSplit1.Value = "0.00"
Me.TbSplit2.Value = "0.00"
Me.TbSplit3.Value = "0.00"
Me.TbSplit4.Value = "0.00"
Me.TbSplit5.Value = "0.00"
Me.TbSplit6.Value = "0.00"
Me.TbPosted.Value = "0.00"
Me.TbUnposted.Value = "0.00"
Call PopulateUserFormTransactionsComboBoxes
End Sub
New module 'ModUserFormTransactions':
Option Explicit
Const nNumberOfComboBOXES = 6
Public bGblTransactionsInhibitUserFormEvents As Boolean
Public sGblComboBoxMasterList() As String
Public iGblCombBoxItemCount As Long
Sub PopulateUserFormTransactionsComboBoxes()
Dim myRange As Range
Dim r As Range
Dim i As Long
Dim iComboBoxNumber As Long
Dim sComboBoxName As String
Dim sValue As String
Dim sIncludeExcludeSentinel As String
'Initialize the Global Master ComboBox List Dynamic Array
iGblCombBoxItemCount = 0
ReDim sGblComboBoxMasterList(1 To 2, 1 To 1)
'Use the Table Header Range to obtain a range containing the List
'of all Possible categories
'If the cell above a Category is BLANK, include that category in the List (by placing 'OK' in the ComboBox List Array)
Set myRange = Sheets("Data").ListObjects(1).HeaderRowRange
For Each r In myRange
sValue = Trim(r.Value)
sIncludeExcludeSentinel = Trim(r.Offset(-1, 0).Value)
If Len(sIncludeExcludeSentinel) = 0 Then
'Increase the capacity of the Global Dynamic Array
iGblCombBoxItemCount = iGblCombBoxItemCount + 1
ReDim Preserve sGblComboBoxMasterList(1 To 2, 1 To iGblCombBoxItemCount)
'Put the Category in the Global Dynamic Array
sGblComboBoxMasterList(1, iGblCombBoxItemCount) = sValue
sGblComboBoxMasterList(2, iGblCombBoxItemCount) = "OK"
Debug.Print r.Column, r.Value, r.Offset(-1, 0).Value
End If
Next r
'Display the contents of the Dynamic Array in the Immediate Window (CTRL G in debugger)
For i = 1 To UBound(sGblComboBoxMasterList, 2)
'Debug.Print i, sGblComboBoxMasterList(1, i), sGblComboBoxMasterList(2, i)
Next i
'Clear each ComboBox
'Put the list in each ComboBox
For iComboBoxNumber = 1 To nNumberOfComboBOXES
sComboBoxName = "CbAllocate" & iComboBoxNumber
Transactions.Controls(sComboBoxName).Clear
For i = 1 To UBound(sGblComboBoxMasterList, 2)
'Debug.Print i, sGblComboBoxMasterList(1, i), sGblComboBoxMasterList(2, i)
sValue = sGblComboBoxMasterList(1, i)
sIncludeExcludeSentinel = sGblComboBoxMasterList(2, i)
If sIncludeExcludeSentinel = "OK" Then
Transactions.Controls(sComboBoxName).AddItem sValue
End If
Next i
Next iComboBoxNumber
End Sub
Sub ProcessUserFormTransactionsComboBoxChangeEvents()
Dim i As Long
Dim iComboBoxNumber As Long
Dim sComboBoxName As String
Dim sActiveComboBoxName As String
Dim sIncludeExcludeSentinel As String
Dim sValue As String
Dim sValueArray As String
Dim sValueTag As String
'Disable UserForm Events
bGblTransactionsInhibitUserFormEvents = True
'Get the name of the ComboBox that changed value
sActiveComboBoxName = Transactions.ActiveControl.Name
'Get the ComboBox 'Value' and 'Previous Value' (Tag Value)
sValue = Transactions.Controls(sActiveComboBoxName).Value
sValueTag = Transactions.Controls(sActiveComboBoxName).Tag
'Remove the 'Value' from the Global Master ComboBox List Dynamic Array
'Add the 'Tag Value' to the Global Master ComboBox List Dynamic Array
For i = 1 To UBound(sGblComboBoxMasterList, 2)
'Debug.Print i, sGblComboBoxMasterList(1, i), sGblComboBoxMasterList(2, i)
sValueArray = sGblComboBoxMasterList(1, i)
If sValueArray = sValue Then
sGblComboBoxMasterList(2, i) = ""
End If
If sValueArray = sValueTag Then
sGblComboBoxMasterList(2, i) = "OK"
End If
Next i
'Save the Current ComboBox 'Value' as the NEW 'Previous Value' (Tag Value)
Transactions.Controls(sActiveComboBoxName).Tag = sValue
'Clear each ComboBox
'Save the value in the ComboBox
'Put the value back in the ComboBox - accidentally erased by the 'Clear' Command
'Put the list in each ComboBox
For iComboBoxNumber = 1 To nNumberOfComboBOXES
sComboBoxName = "CbAllocate" & iComboBoxNumber
sValue = Transactions.Controls(sComboBoxName).Value
Transactions.Controls(sComboBoxName).Clear 'This command Triggers a ComboBox Change Event
Transactions.Controls(sComboBoxName).Value = sValue 'This command Triggers a ComboBox Change Event
For i = 1 To UBound(sGblComboBoxMasterList, 2)
'Debug.Print i, sGblComboBoxMasterList(1, i), sGblComboBoxMasterList(2, i)
sValue = sGblComboBoxMasterList(1, i)
sIncludeExcludeSentinel = sGblComboBoxMasterList(2, i)
If sIncludeExcludeSentinel = "OK" Then
Transactions.Controls(sComboBoxName).AddItem sValue
End If
Next i
Next iComboBoxNumber
'Enable UserForm Events
bGblTransactionsInhibitUserFormEvents = False
End Sub
Lewis
Bookmarks