我是 Monching,有没有人可以帮助我解决我的 excel vbs 代码,因为我是这项工作的新手。“复制到数据库有一些无法解决的问题。我需要该条目依赖于 2 cbo。
当我将数据放入用户表单时,数据会覆盖同一单元格中的其他数据。我需要在用户表单中输入的金额取决于 cboMembers 和 cboMonth。如果我选择成员和月份之一,我需要条目特定于成员和月份的单元格。
Private Sub cboMembers_Change()
End Sub
Private Sub cboMonth_Change()
End Sub
Private Sub cmdCancel_Click()
' Clear the form
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdEnter_Click()
Dim iRow As Long
Dim ws As Worksheet
If OptionButton1 Then Set ws = Worksheets("Share")
If OptionButton2 Then Set ws = Worksheets("Salary")
If OptionButton3 Then Set ws = Worksheets("Emer")
If OptionButton4 Then Set ws = Worksheets("Bday")
If OptionButton5 Then Set ws = Worksheets("Educ")
On Error Resume Next
iRow = ws.Cells.Find("*", Range("B2"), xlFormulas, , xlByRows, xlPrevious).Row
On Error GoTo 0
iRow = iRow + 0
' Check user input
If Me.cboMembers.Value = "" Then
MsgBox "Please choose a Members.", vbExclamation, "UserForm1"
Me.cboMembers.SetFocus
Exit Sub
End If
If Me.cboMonth.Value = "" Then
MsgBox "Please choose a Month.", vbExclamation, "UserForm1"
Me.cboMonth.SetFocus
Exit Sub
End If
If Me.txtAmountPaid.Value = "" Then
MsgBox "Please enter an Amount.", vbExclamation, "UserForm1"
Me.txtAmountPaid.SetFocus
Exit Sub
End If
If Not IsNumeric(Me.txtAmountPaid.Value) Then
MsgBox "The Amount box must contain a number.", vbExclamation, "UserForm1"
Me.txtAmountPaid.SetFocus
Exit Sub
End If
'copy the data to the database
RowCount = Worksheets("Share").Range("B2").CurrentRegion.Rows.Count
With Worksheets("Share").Range("B2")
.Offset(RowCount, 0).Value = Me.cboMembers.Value
.Offset(RowCount, 0).Value = Me.cboMonth.Value
.Offset(RowCount, 1).Value = Me.txtAmountPaid.Value
End With
'clear the data
Me.cboMembers.Value = ""
Me.cboMonth.Value = ""
Me.txtAmountPaid.Value = ""
Me.OptionButton1.Value = ""
Me.OptionButton2.Value = ""
Me.OptionButton3.Value = ""
Me.OptionButton4.Value = ""
Me.OptionButton5.Value = ""
End Sub
Private Sub UserForm_Initialize()
Dim cmonth As Range
Dim ws As Worksheet
Set ws = Worksheets("LookUpEntry")
For Each cmonth In ws.Range("Month")
With Me.cboMonth
.AddItem cmonth.Value
End With
Next cmonth
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please Use the Close Button!"
End If
End Sub
这是我的useform,成员和月份都在表格中。当我选择成员和相应的月份时,我希望将支付金额中的值写在特定的单元格中。如果我选择股份,所支付金额的价值会自动输入股份表中。如果我在 A4 中选择会员,在 F1 中选择月份,则支付金额的价值将在 F4 中。我需要那个代码。
我的表格
A2 到 A234 是我的会员
B1 到 M1 是我的月份