ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Hi,
The code is shown below.
I have a userform with Comboboxes
ComboBox1 is MONTH
ComboBox2 is YEAR
Month is to be inserted into cell A3
Year is to be inserted into cell C3
When i press my transfer button the YEAR isnt shown on the worksheet but the MONTH is entered into cell A3
Please can you check / advise where i went wrong.
Thanks
The code is shown below.
I have a userform with Comboboxes
ComboBox1 is MONTH
ComboBox2 is YEAR
Month is to be inserted into cell A3
Year is to be inserted into cell C3
When i press my transfer button the YEAR isnt shown on the worksheet but the MONTH is entered into cell A3
Please can you check / advise where i went wrong.
Thanks
Code:
Private Sub TransferButton_Click()
Dim i As Integer
Dim ControlsArr As Variant, ctrl As Variant
Dim x As Long
For i = 1 To 2
With Me.Controls("ComboBox" & i)
If .ListIndex = -1 Then
MsgBox "MUST SELECT BOTH OPTIONS", 48, "MONTH & YEAR TRANSFER MESSAGE"
.SetFocus
Exit Sub
End If
End With
Next i
ControlsArr = Array(Me.ComboBox1, Me.ComboBox2)
With ThisWorkbook.Worksheets("G INCOME")
For i = 0 To UBound(ControlsArr)
Select Case i
Case 1, 2, 4
.Cells(3, i + 1) = IIf(IsNumeric(ControlsArr(i)), Val(ControlsArr(i)), ControlsArr(i))
Case Else
.Cells(3, i + 1) = ControlsArr(i)
ControlsArr(i).Text = ""
End Select
Next i
End With
ActiveWorkbook.Save
Application.ScreenUpdating = True
MsgBox "Month & Year Have Been Updated", vbInformation, "SUCCESSFUL MESSAGE INCOME MONTH & YEAR"
Unload INCOMEMONTHYEAR
End Sub