excel2010中的VBA代码
我很抱歉,有没有人可以帮我解决我的excel vbs代码,因为我是这项工作的新手。 “复制到数据库”有一些无法解决的问题。我需要该条目依赖于2 cbo 当我将数据放入userform时,数据会覆盖同一单元格中的其他数据。 我需要在userform中输入的金额取决于cboMembers和cboMonth。如果我选择其中一个成员和月份,我需要该条目特定于成员和月份的单元格excel2010中的VBA代码,excel,vba,Excel,Vba,我很抱歉,有没有人可以帮我解决我的excel vbs代码,因为我是这项工作的新手。 “复制到数据库”有一些无法解决的问题。我需要该条目依赖于2 cbo 当我将数据放入userform时,数据会覆盖同一单元格中的其他数据。 我需要在userform中输入的金额取决于cboMembers和cboMonth。如果我选择其中一个成员和月份,我需要该条目特定于成员和月份的单元格 Private Sub cboMembers_Change() End Sub Private Sub cboMonth_C
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是我的月份我认为问题可能在于代码的这一部分:
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
您正在将cboMembers
中的值复制到单元格(行计数+2,2)
。然后将cboMonth
的值复制到同一单元格中-覆盖先前放置在该单元格中的cboMembers
中的值
您试图做什么还不是100%清楚,但这段代码可能会更好:
With Worksheets("Share").Range("B2")
.Offset(RowCount, 0).Value = Me.cboMembers.Value
.Offset(RowCount, 1).Value = Me.cboMonth.Value
.Offset(RowCount, 2).Value = Me.txtAmountPaid.Value
End With
不清楚你在问什么。请澄清你的具体问题或添加其他详细信息,以突出你需要的内容。按照目前的书面形式,很难准确说出你在问什么。你能先回答你的问题,让标题更有意义吗(你除了标签信息什么都没有,根本不属于那里,而且它没有说明你要问的问题),然后解释你的问题到底是什么?发布一大块代码(顺便说一句,不是
VBS
)是不够的。我不知道这里的实际问题是什么。谢谢。