我创建了一个用户表单,填充了一个电子表格,我已将代码添加到"输入"按钮。 我一直收到错误450,请指教。我从之前使用的代码中复制了这种格式,没有任何错误。唯一新的东西是第一个Sub中的if then语句。
Private Sub cmdEnter_Click()
On Error Resume Next
If cmbcash.Value = "yes" Then
Sheets(Sheet1).[a1].Value = frmInput.txtCash
Sheets(Sheet1).[a2].Value = frmInput.txtCash
Else
Sheets(Sheet1).[a2].Value = frmInput.txtcash2
If cmbstock.Value = "yes" Then
Sheets(Sheet1).[b1].Value = frmInput.txtstock
Sheets(Sheet1).[b2].Value = frmInput.txtstock
Else
Sheets(Sheet1).[b2].Value = frmInput.txtstock2
If cmbdeposits.Value = "yes" Then
Sheets(Sheet1).[c1].Value = frmInput.txtdeposits
Sheets(Sheet1).[c2].Value = frmInput.txtdeposits
Else
Sheets(Sheet1).[c2].Value = frmInput.txtdeposits2
End If
Hide Me
End Sub
Private Sub UserForm_Initialize()
Dim x
Dim y
y = Array("Transfer", "Don't Transfer", "Retirement at 75%")
x = Array("Yes", "No")
cmbcash.Value = " "
cmbstock.Value = " "
cmbdeposits.Value = " "
cmbcash.List = x
cmbstock.List = x
cmbdeposits.List = x
End Sub
答案 0 :(得分:0)
每个End If
都需要If
。您还应该删除On Error Resume Next
- 修复错误,不要忽略它们,否则会产生意想不到的结果!
Private Sub cmdEnter_Click()
If cmbcash.Value = "yes" Then
Sheets(Sheet1).[a1].Value = frmInput.txtCash
Sheets(Sheet1).[a2].Value = frmInput.txtCash
Else
Sheets(Sheet1).[a2].Value = frmInput.txtcash2
END if
If cmbstock.Value = "yes" Then
Sheets(Sheet1).[b1].Value = frmInput.txtstock
Sheets(Sheet1).[b2].Value = frmInput.txtstock
Else
Sheets(Sheet1).[b2].Value = frmInput.txtstock2
END if
If cmbdeposits.Value = "yes" Then
Sheets(Sheet1).[c1].Value = frmInput.txtdeposits
Sheets(Sheet1).[c2].Value = frmInput.txtdeposits
Else
Sheets(Sheet1).[c2].Value = frmInput.txtdeposits2
End If
Hide Me
End Sub