I have a user form with a search combo box that fills text and other combo boxes with data from a specific worksheet. When I select the "New" command button I'm trying to fill the combo boxes with data from another worksheet.
</create>
Code:
Option Explicit
Private Sub UserForm_Activate()
cmdNew.Enabled = True
cmdClear.Enabled = False
cmdSave.Enabled = False
cmdDelete.Enabled = False
cmdUpdate.Enabled = False
LoadDataList
End Sub
Private Function LoadDataList() As Boolean
Dim Ws As Worksheet
Dim Rng As Range
Dim C As Range
Dim Data As Object
Dim k As Variant
Set Data = CreateObject("System.Collections.ArrayList")
'Get Records definition
Set Ws = ThisWorkbook.Worksheets("LDataBaseCabinets")
Set Rng = Ws.Range("A:A")
'clear combobox
cboSearch.Clear
'load array
For Each C In Rng.Cells
If C.Value <> "" Then
Data.Add C.Value
End If
Next
'Sort array
Data.Sort
For Each k In Data
cboSearch.AddItem k
Next
Set Rng = Nothing
Set Ws = Nothing
Set Data = Nothing
End Function
Private Sub cboSearch_AfterSave()
'Every change of the dropdown get the value
Dim findString As String
Dim iRow As Integer
Dim Rng As Range
Dim Ws As Worksheet
Set Ws = Worksheets("LDataBaseCabinets")
findString = cboSearch.Text
lblRowID.Caption = ""
If findString <> "" Then
With Sheets("LDataBaseCabinets").Range("A:A")
Set Rng = .Find(What:=findString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
'store found row in lblRowID, a hidden field on form
lblRowID.Caption = Rng.Row
End If
End With
End If
If lblRowID.Caption <> "" Then
'load values on form
iRow = Val(lblRowID.Caption)
Me.tbxNumber.Value = Ws.Cells(iRow, 1).Value
Me.tbxStyle.Value = Ws.Cells(iRow, 2).Value
Me.cboCab1.Value = Ws.Cells(iRow, 3).Value
Me.cboCab2.Value = Ws.Cells(iRow, 4).Value
Me.cboCab3.Value = Ws.Cells(iRow, 5).Value
Me.cboCab4.Value = Ws.Cells(iRow, 6).Value
Me.cboCab5.Value = Ws.Cells(iRow, 7).Value
Me.cboCab6.Value = Ws.Cells(iRow, 8).Value
Me.cboCab7.Value = Ws.Cells(iRow, 9).Value
Me.cboCab8.Value = Ws.Cells(iRow, 10).Value
Me.cboCab9.Value = Ws.Cells(iRow, 11).Value
Me.cboCab10.Value = Ws.Cells(iRow, 12).Value
cmdNew.Enabled = False
cmdClear.Enabled = True
cmdSave.Enabled = True
cmdDelete.Enabled = True
cmdUpdate.Enabled = False
Set Ws = Nothing
End If
End Sub
Private Sub cboSearch_DropButt*******()
'Every change of the dropdown get the value
Dim findString As String
Dim iRow As Integer
Dim Rng As Range
Dim Ws As Worksheet
Set Ws = Worksheets("LDataBaseCabinets")
findString = cboSearch.Text
lblRowID.Caption = ""
If findString <> "" Then
With Sheets("LDataBaseCabinets").Range("A:A")
Set Rng = .Find(What:=findString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
'store found row in lblRowID, a hidden field on form
lblRowID.Caption = Rng.Row
End If
End With
End If
If lblRowID.Caption <> "" Then
'load values on form
iRow = Val(lblRowID.Caption)
Me.tbxNumber.Value = Ws.Cells(iRow, 1).Value
Me.tbxStyle.Value = Ws.Cells(iRow, 2).Value
Me.cboCab1.Value = Ws.Cells(iRow, 3).Value
Me.cboCab2.Value = Ws.Cells(iRow, 4).Value
Me.cboCab3.Value = Ws.Cells(iRow, 5).Value
Me.cboCab4.Value = Ws.Cells(iRow, 6).Value
Me.cboCab5.Value = Ws.Cells(iRow, 7).Value
Me.cboCab6.Value = Ws.Cells(iRow, 8).Value
Me.cboCab7.Value = Ws.Cells(iRow, 9).Value
Me.cboCab8.Value = Ws.Cells(iRow, 10).Value
Me.cboCab9.Value = Ws.Cells(iRow, 11).Value
Me.cboCab10.Value = Ws.Cells(iRow, 12).Value
cmdNew.Enabled = False
cmdClear.Enabled = True
cmdSave.Enabled = True
cmdDelete.Enabled = True
cmdUpdate.Enabled = False
End If
End Sub
Private Sub cmdNew_Click()
'this clears the combo box and disables it
'it also clears the form fields
'clear the data
Me.cboSearch = ""
Me.tbxNumber = ""
Me.tbxStyle = ""
Me.cboCab1 = ""
Me.cboCab2 = ""
Me.cboCab3 = ""
Me.cboCab4 = ""
Me.cboCab5 = ""
Me.cboCab6 = ""
Me.cboCab7 = ""
Me.cboCab8 = ""
Me.cboCab9 = ""
Me.cboCab10 = ""
Me.lblRowID = ""
cboSearch.Text = "<create model="" new="">"
tbxNumber.SetFocus
cboSearch.Enabled = False
cboCab1.Enabled = True
cboCab2.Enabled = True
cboCab3.Enabled = True
cboCab4.Enabled = True
cboCab5.Enabled = True
cboCab6.Enabled = True
cboCab7.Enabled = True
cboCab8.Enabled = True
cboCab9.Enabled = True
cboCab10.Enabled = True
cmdNew.Enabled = False
cmdSave.Enabled = True
cmdClear.Enabled = True
cmdDelete.Enabled = False
cmdUpdate.Enabled = False
End Sub
Private Sub cmdClear_Click()
'clear the data
Me.cboSearch = ""
Me.tbxNumber = ""
Me.tbxStyle = ""
Me.cboCab1 = ""
Me.cboCab2 = ""
Me.cboCab3 = ""
Me.cboCab4 = ""
Me.cboCab5 = ""
Me.cboCab6 = ""
Me.cboCab7 = ""
Me.cboCab8 = ""
Me.cboCab9 = ""
Me.cboCab10 = ""
cboSearch.Value = ""
cboSearch.Enabled = True
cboSearch.SetFocus
cmdNew.Enabled = True
cmdClear.Enabled = False
cmdSave.Enabled = False
cmdDelete.Enabled = False
cmdUpdate.Enabled = False
End Sub
Private Sub cmdDelete_Click()
'This will allow the deleting of a Ticket record by using the Ticket row on the sheet
Dim iRow As Integer
'Prompt user its ok to delete
If MsgBox("Are you sure you want to delete this Model?", vbYesNo) = vbYes Then
'Then delete row
'Set row based on drop down in Search Model Number drop down
iRow = Val(lblRowID.Caption)
Worksheets("LDataBaseCabinets").Rows(iRow).EntireRow.Delete
Else
Exit Sub 'Exit back to screen
End If
'clear the data
Me.tbxNumber = ""
Me.tbxStyle = ""
Me.cboCab1 = ""
Me.cboCab2 = ""
Me.cboCab3 = ""
Me.cboCab4 = ""
Me.cboCab5 = ""
Me.cboCab6 = ""
Me.cboCab7 = ""
Me.cboCab8 = ""
Me.cboCab9 = ""
Me.cboCab10 = ""
Me.cboSearch.Enabled = True
Me.cboSearch.SetFocus
Me.cboSearch.Value = ""
cmdNew.Enabled = True
cmdClear.Enabled = False
cmdSave.Enabled = False
cmdDelete.Enabled = False
cmdUpdate.Enabled = False
End Sub
Private Sub CmdSave_Click()
Dim Ws As Worksheet
Set Ws = Worksheets("LDataBaseCabinets")
'This will update a Model record
'It sends the rowID to the form. A Blank row means ADD
Dim iRow As Integer
'Set row based on drop down in Search Model Number drop down
iRow = Val(lblRowID.Caption)
'check if row found or adding
If iRow = 0 Then 'new Model
'find first empty row in database
iRow = Ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
End If
'copy the data to the database
Ws.Cells(iRow, 1).Value = Me.tbxNumber.Value
Ws.Cells(iRow, 2).Value = Me.tbxStyle
Ws.Cells(iRow, 3).Value = Me.cboCab1.Value
Ws.Cells(iRow, 4).Value = Me.cboCab2.Value
Ws.Cells(iRow, 5).Value = Me.cboCab3.Value
Ws.Cells(iRow, 6).Value = Me.cboCab4.Value
Ws.Cells(iRow, 7).Value = Me.cboCab5.Value
Ws.Cells(iRow, 8).Value = Me.cboCab6.Value
Ws.Cells(iRow, 9).Value = Me.cboCab7.Value
Ws.Cells(iRow, 10).Value = Me.cboCab8.Value
Ws.Cells(iRow, 11).Value = Me.cboCab9.Value
Ws.Cells(iRow, 12).Value = Me.cboCab10.Value
'clear the data
Me.tbxNumber = ""
Me.tbxStyle = ""
Me.cboCab1 = ""
Me.cboCab2 = ""
Me.cboCab3 = ""
Me.cboCab4 = ""
Me.cboCab5 = ""
Me.cboCab6 = ""
Me.cboCab7 = ""
Me.cboCab8 = ""
Me.cboCab9 = ""
Me.cboCab10 = ""
Me.cboSearch.Enabled = True
Me.cboSearch.Value = ""
Me.cboSearch.SetFocus
cmdNew.Enabled = True
cmdClear.Enabled = False
cmdSave.Enabled = False
cmdDelete.Enabled = False
cmdUpdate.Enabled = False
LoadDataList
Set Ws = Nothing
End Sub
Private Sub CmdClose_Click()
Unload Me
End Sub
Private Sub cboCab1_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab1.RowSource = ""
iLastRowUsed = Ws.Columns("A").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'A'
sRange = "A2:A" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab1.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab1_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("A").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'A'
sRowSource = "'LBaseCabinets'!A2:A" & iLastRowUsed
'Populate the ComboBoxes
cboCab1.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab2_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab2.RowSource = ""
iLastRowUsed = Ws.Columns("H").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'H'
sRange = "H2:H" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab2.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab2_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("H").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'H'
sRowSource = "'LBaseCabinets'!H2:H" & iLastRowUsed
'Populate the ComboBoxes
cboCab2.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab3_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab3.RowSource = ""
iLastRowUsed = Ws.Columns("O").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'O'
sRange = "O2:O" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab3.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab3_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("H").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'H'
sRowSource = "'LBaseCabinets'!H2:H" & iLastRowUsed
'Populate the ComboBoxes
cboCab3.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab4_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab4.RowSource = ""
iLastRowUsed = Ws.Columns("V").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'V'
sRange = "V2:V" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab4.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab4_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("V").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'V'
sRowSource = "'LBaseCabinets'!V2:V" & iLastRowUsed
'Populate the ComboBoxes
cboCab4.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab5_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab5.RowSource = ""
iLastRowUsed = Ws.Columns("AC").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AC'
sRange = "AC2:AC" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab5.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab5_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("AC").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AC'
sRowSource = "'LBaseCabinets'!AC2:AC" & iLastRowUsed
'Populate the ComboBoxes
cboCab5.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab6_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab6.RowSource = ""
iLastRowUsed = Ws.Columns("AJ").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AJ'
sRange = "AJ2:AJ" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab6.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab6_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("AJ").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AJ'
sRowSource = "'LBaseCabinets'!AJ2:AJ" & iLastRowUsed
'Populate the ComboBoxes
cboCab6.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab7_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab7.RowSource = ""
iLastRowUsed = Ws.Columns("AQ").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AQ'
sRange = "AQ2:AQ" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab7.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab7_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("AQ").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AQ'
sRowSource = "'LBaseCabinets'!AQ2:AQ" & iLastRowUsed
'Populate the ComboBoxes
cboCab7.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab8_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab8.RowSource = ""
iLastRowUsed = Ws.Columns("AX").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AX'
sRange = "AX2:AX" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab8.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab8_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("AX").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'AX'
sRowSource = "'LBaseCabinets'!AX2:AX" & iLastRowUsed
'Populate the ComboBoxes
cboCab8.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab9_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab9.RowSource = ""
iLastRowUsed = Ws.Columns("BE").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'BE'
sRange = "BE2:BE" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab9.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab9_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("BE").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'BE'
sRowSource = "'LBaseCabinets'!BE2:BE" & iLastRowUsed
'Populate the ComboBoxes
cboCab9.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Private Sub cboCab10_Change()
Dim Ws As Worksheet
Dim myRange As Range
Dim oData As Object
Dim R As Range
Dim i As Long
Dim iLastRowUsed As Long
Dim sRange As String
Dim sValue As String
Set oData = CreateObject("System.Collections.ArrayList")
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
cboCab10.RowSource = ""
iLastRowUsed = Ws.Columns("BL").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'BL'
sRange = "BL2:BL" & iLastRowUsed
Set myRange = Ws.Range(sRange)
'load array
For Each R In myRange
sValue = CStr(Trim(R.Value)) 'Remove leading/trailing spaces and make sure the data is a string value
oData.Add sValue
Next
'Look at the data during Software Development before sorting in the Immediate Window (CTRL G in debugger)
Debug.Print oData.Count
For i = 0 To oData.Count - 1
Debug.Print oData(i)
Next i
'Sort array
oData.Sort
'Put the values in the ComboBox
For i = 0 To oData.Count - 1
cboCab10.AddItem oData(i)
Next i
'Clear object pointers
Set myRange = Nothing
Set Ws = Nothing
Set oData = Nothing
End Sub
Private Sub cboCab10_DropButt*******()
Dim Ws As Worksheet
Dim iLastRowUsed As Long
Dim sRowSource As String
'Create the Worksheet Object
Set Ws = ThisWorkbook.Worksheets("LBaseCabinets")
iLastRowUsed = Ws.Columns("BL").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If iLastRowUsed < 2 Then
iLastRowUsed = 2
End If
'Get the Range that contains data in Column 'BL'
sRowSource = "'LBaseCabinets'!BL2:BL" & iLastRowUsed
'Populate the ComboBoxes
cboCab10.RowSource = sRowSource
'Clear object pointers
Set Ws = Nothing
End Sub
Last edited by a moderator: