好的.....我认为我已经对语言有了足够深入的理解,可以用它来推进。此更新是我的代码的完整修订版本,我将尽可能详细说明。
计划目标: 1.)创建允许用户记录数据的Userform。(工作) 2.)允许组合框写入充当数据库的列表。(我有一个名为3.的动态范围集。)3。)ulMech是使用名称管理器创建的,是带有偏移的complet,列表扩展了) 4.)userform是一个多标签用户表单,其中包含特定于每个列表的选项卡。 5.)将所有数据填充到表1上的特定单元格集(工作)。
单击添加原因时需要新的错误对象。
我还在列中添加了引用条目号,以便我可以使用此编辑之前提交的循环。
我的代码:
Private Sub CheckBox2_Click()
End Sub
Private Sub ComboBox1_Change()
End Sub
Private Sub cmAdd_Click()
Add_Reason
Update_Combo
End Sub
Private Sub CommandButton1_Click()
Dim emptyCell As Long
Dim cellD As Long
'Make Sheet1 active
Sheet1.Activate
'Determine Empty Cell
emptyCell = WorksheetFunction.CountA(Range("L:L")) + 1
'Determine empty cell date
cellDate = WorksheetFunction.CountA(Range("K:K")) + 1
If CheckBoxM.Value = True Then Cells(emptyCell, 12).Value = CheckBoxM.Caption
If CheckBoxS.Value = True Then Cells(emptyCell, 12).Value = Cells(emptyCell, 12).Value & " " & CheckBoxS.Caption
If CheckBoxE.Value = True Then Cells(emptyCell, 12).Value = Cells(emptyCell, 12).Value & " " & CheckBoxE.Caption
'Transfer Data tO Sheet.
Cells(cellDate, 11).Value = TextBoxULD.Value
End Sub
Private Sub CommandButtonP1S_Click()
Begin
Dim emptyRow As Long
'Make Sheet1 active
Sheet1.Activate
'Determine Empty Row
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer Information To Next available Row.
Cells(emptyRow, 1).Value = TextBoxDate.Value
Cells(emptyRow, 2).Value = TextBoxWeek.Value
Cells(emptyRow, 3).Value = TextBoxBN.Value
Cells(emptyRow, 4).Value = TextBoxBT.Value
Cells(emptyRow, 5).Value = TextBoxST.Value
Cells(emptyRow, 6).Value = TextBoxTD.Value
Cells(emptyRow, 7).Value = TextBoxY.Value
End Sub
Private Sub CommandButtonT1C_Click()
UserForm.Hide
End Sub
Private Sub Frame2_Click()
Frame2.Hide
End Sub
Private Sub MultiPage1_Change()
End Sub
'Filling the ComboBox
Public ws As Worksheet
Const wsName As String = "ulMech"
Set ws = ThisWorkbook.Sheets(dbSheet)
Update_Combo
Sub Begin()
'Do Things
MsgBox frmMain.CmBox1.ListCount & ""
End Sub
Sub Add_Reason()
Dim r As Long
Dim s As String
s = frmMain.CmBox1 'Error occurs here object required
With ws
Do
r = r + 1
Loop Until .Cells(r, 1) = ""
.Cells(r, 1) = r + 1
.Cells(r, 2) = s
End With
End Sub
Sub Delete_Reason()
Dim r As Long
Dim s As String
s = frmMain.CmBox1
With ws
Do
r = r + 1
Loop Until .Cells(r, 2) = s
.Rows(r).Delete
End With
End With
End Sub
Sub Update_Combo()
Dim r As Long
Dim c As Integer
frmMain.CmBox1.Clear
With ws
If IsNumeric(.Cells(r, 1)) Then
.Cells(r, 1) = r
frmMain.CmBox1.AddItem .Cells(r, 2)
End If
Next r
End Sub
Private Sub UserForm_Initialize()
'Set Empty Text Box Values
TextBoxDate.Value = ""
TextBoxBN.Value = ""
TextBoxBT.Value = ""
TextBoxST.Value = ""
TextBoxTD.Value = ""
TextBoxY.Value = ""
TextBoxULD.Value = ""
'Set checkbox values to false
CheckBoxM.Value = False
CheckBoxS.Value = False
CheckBoxE.Value = False
End Sub
继承我的数据库,我正在打印到ul mechanical,其名称为ulMech。一旦我开始这样做,只会改变范围并复制代码。
提交按钮处理将数据打印到第一张适用于复选框和日期等的数据。我已经打印了组合框代码,因为我想让数据库更新正常工作,然后无法整理。
添加原因按钮用于将原因添加到列表中。我将添加一个关闭按钮。我会在以后运行删除代码。
每个标签专用于特定类型的数据,因此程序清晰易用。他们使用的程序不清晰或易于使用,所以我被要求简单化。
这是sheet1(数据将打印到每个单元格,以便可以生成统计报告以及图表。这不是很重要因为它起作用....现在....
这是将更新组合框的工作表ulMech是我们关注的。该表称为dbSheets。
我希望这很清楚,我非常接近解决它我只是在一个星期左右的语言,所以我仍然可以掌握它。我希望这是清楚和简洁的。感谢您的时间。我无法发布图片,因为我需要十个或更多的重复点=(
答案 0 :(得分:0)
当例程进入第一个循环时,你的findblank变量值为0,这会导致程序发送异常。首先将其设置为1。
可能你的意思是findblank = findblank = 1>> findblank = findblank + 1
但我不确定找到空白点会让你更新表格中的combobox.item。
我建议您删除所有评论,然后重写组合框中的所有项目。
Private Sub ComboBoxUL_Change()
Dim rng As Range
Set rng = ThisWorkbook.Worksheets("sheet2").Range(<initial range for list>)
rng.CurrentRegion.ClearContents
Dim RowCount As Integer
RowCount = ComboBoxUL.ListCount
For x = 1 To RowCount
rng.Cells(x, 1) = ComboBoxUL.List(0, x - 1)
Next x
End Sub
答案 1 :(得分:0)
专用工作表以包含列表内容。 2列。第1列是条目编号,第2列是“原因”。
Column
A B
Row --- ---
1 1 Reason1 ' Instead of having the first entry here you could use this row for headers
2 2 Reason2
3 3 Reason3
4 4 Reason4
5 5 Reason5
1 CommandButton to“Add”&amp; 1到“删除” 也许标准的“提交”&amp; “关闭”也是如此。
编写“添加”程序的代码,该程序取当前值 组合框并将其放在“CBoxList”列表的底部 工作表。
编写“删除”程序的代码,该程序获取组合框的当前值并在“CBoxList”工作表中找到并删除 那一行。
编写“更新CBox”程序的代码,该程序在初始化表单,添加值和删除时删除时运行 值。此过程将清除表单组合框并重新添加所有 “CBoxList”工作表中的项目到组合框。
Public ws As Worksheet ' This will be referenced within the form subs and functions
Const wsName As String = "CBoxList"
Private Sub UserForm_Initialize()
Set ws = ThisWorkbook.Sheets(wsName) ' Initialize variable
Update_Combo
End Sub
Private Sub cmdSubmit_Click()
Begin ' Main Procedure
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdAdd_Click()
Add_Reason
Update_Combo
End Sub
Private Sub cmdDelete_Click()
Delete_Reason
Update_Combo
End Sub
Sub Begin()
' Do_Things
MsgBox frmMain.cmbReason.ListCount & " Reasons."
End Sub
Sub Add_Reason()
Dim r As Long
Dim s As String
s = frmMain.cmbReason
With ws
Do
r = r + 1
Loop Until .Cells(r, 1) = ""
.Cells(r, 1) = r ' If the worksheet list has a header then use: ' .Cells(r,1) = r + 1
.Cells(r, 2) = s
End With
End Sub
Sub Delete_Reason()
Dim r As Long
Dim s As String
s = frmMain.cmbReason
With ws
Do
r = r + 1
Loop Until .Cells(r, 2) = s
.Rows(r).Delete
End With
End Sub
Sub Update_Combo()
Dim r As Long, c As Integer
frmMain.cmbReason.Clear
With ws
For r = 1 To .UsedRange.Rows.Count
If IsNumeric(.Cells(r, 1)) Then
.Cells(r, 1) = r 'Reset ID instance
frmMain.cmbReason.AddItem .Cells(r, 2)
End If
Next r
End With
End Sub