ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Hi,
Here is my code which needs a checkover please.
I had changed from 9 comboboxes to two textboxes and 7 comboboxes.
I am not sure what needs to be changed in the line With Me.Controls("ComboBox" & i)
Here is my code which needs a checkover please.
I had changed from 9 comboboxes to two textboxes and 7 comboboxes.
I am not sure what needs to be changed in the line With Me.Controls("ComboBox" & i)
VBA Code:
Private Sub CommandButton1_Click()
Dim i As Integer
Dim ControlsArr As Variant, ctrl As Variant
Dim x As Long
For i = 1 To 9
With Me.Controls("ComboBox" & i)
If .ListIndex = -1 Then
MsgBox "MUST SELECT ALL OPTIONS", 48, "MC LIST TRANSFER"
.SetFocus
Exit Sub
End If
End With
Next i
ControlsArr = Array(Me.TextBox1, Me.TextBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox6, Me.ComboBox7, Me.ComboBox8, Me.ComboBox9)
With ThisWorkbook.Worksheets("MC LIST")
.Range("A8").EntireRow.Insert Shift:=xlDown
.Range("A8:I8").Borders.Weight = xlThin
For i = 0 To UBound(ControlsArr)
Select Case i
Case 1, 2, 4
.Cells(4, i + 1) = IIf(IsNumeric(ControlsArr(i)), Val(ControlsArr(i)), ControlsArr(i))
Case Else
.Cells(4, i + 1) = ControlsArr(i)
ControlsArr(i).Text = ""
End Select
Next i
End With
Application.ScreenUpdating = False
With Sheets("MC LIST")
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("A7:I" & x).Sort Key1:=Range("A8"), Order1:=xlAscending, Header:=xlGuess
End With
ActiveWorkbook.Save
Application.ScreenUpdating = True
Sheets("MC LIST").Range("A8").Select
MsgBox "Database Has Been Updated", vbInformation, "SUCCESSFUL MESSAGE"
Unload McListForm
End Sub