在用户表单中设置组合框的条件

Setting condition for the combo box in a user form

您好,目前我有一个用户表单,看起来像这样用于添加新项目:

在组合框中,用户可以 select "Big Project"、"Medium Project" 和 "Small Project" 大小。每个项目大小都包含 sheet 中的特定范围,如下所示:

用户将项目详细信息添加到用户表单中,select项目大小的组合框下拉列表,新项目详细信息将添加到每个特定项目大小下的空行中。不幸的是,我不确定如何在组合框下拉列表中调整每个项目的大小,以便当用户已经 select 编辑了项目大小并单击添加命令按钮时,新项目详细信息将添加到 selected 项目大小的新行中。此外,我在下面显示的代码中显示 'Application-defined or object-defined error' 的命令添加按钮有一些问题,并且不确定这些代码是否有助于添加到特定项目大小的 lastrow 中。我完全不知道如何为组合框和命令添加按钮做些什么。

Private Sub CommandAddButton1_Click()

lastrow = Sheets("Program status summary").Range("B").End(xlDown).Row 'shows the above mention error'

    Cells(lastrow + 1, "B").Value = TextBoxProjCode.Text
    Cells(lastrow + 1, "C").Value = TextBoxProjName.Text
    Cells(lastrow + 1, "D").Value = TextBoxSector.Text
    Cells(lastrow + 1, "E").Value = TextBoxObjective.Text
    Cells(lastrow + 1, "H").Value = TextBoxProjSponsor.Text
    Cells(lastrow + 1, "G").Value = TextBoxProjSponsorNew.Text
    Cells(lastrow + 1, "F").Value = TextBoxProjM.Text
    Cells(lastrow + 1, "T").Value = TextBoxRegulatory.Text
    Cells(lastrow + 1, "N").Value = TextBoxRiskLvl.Text
    Cells(lastrow + 1, "M").Value = TextBoxDatePar.Text
    Cells(lastrow + 1, "J").Value = TextBoxCostPar.Text
    Cells(lastrow + 1, "O").Value = TextBoxAffectCust.Text
    Cells(lastrow + 1, "Q").Value = TextBoxCustNonRetail.Text
    Cells(lastrow + 1, "P").Value = TextBoxCustRetail.Text
    Cells(lastrow + 1, "S").Value = TextBoxOutsourcingImp.Text
    Cells(lastrow + 1, "R").Value = TextBoxKeyStatus.Text
    Cells(lastrow + 1, "K").Value = TextBoxSchStart.Text
    Cells(lastrow + 1, "L").Value = TextBoxSchEnd.Text
    Cells(lastrow + 1, "V").Value = TextBoxRagSchedule.Text
    Cells(lastrow + 1, "U").Value = TextBoxRagFinancial.Text
    Cells(lastrow + 1, "W").Value = TextBoxRagBenefit.Text
    Cells(lastrow + 1, "I").Value = TextBoxCost.Text

Unload AddProject

End Sub

我真的希望任何人都可以帮助我在项目大小的组合框中插入每个项目大小的范围和添加命令按钮上的错误。任何帮助,将不胜感激。谢谢。

Private Sub CommandAddButton1_Click()
  Dim sh As Worksheet: Set sh = ThisWorkbook.Sheets("Program status summary")
  Dim emptyRow As Integer: emptyRow = 1 + sh.UsedRange.Find(ComboBoxProjSizes.Text).End(xlDown).row

  With sh
    .Cells(emptyRow, "A").Value = 1 + Application.Max(.Columns(1)) ' to generate a new identifier in column 1

    .Cells(emptyRow, "B").Value = TextBoxProjCode.Text
    .Cells(emptyRow, "C").Value = TextBoxProjName.Text
    .Cells(emptyRow, "D").Value = TextBoxSector.Text
    .Cells(emptyRow, "E").Value = TextBoxObjective.Text
    .Cells(emptyRow, "H").Value = TextBoxProjSponsor.Text
    .Cells(emptyRow, "G").Value = TextBoxProjSponsorNew.Text
    .Cells(emptyRow, "F").Value = TextBoxProjM.Text
    .Cells(emptyRow, "T").Value = TextBoxRegulatory.Text
    .Cells(emptyRow, "N").Value = TextBoxRiskLvl.Text
    .Cells(emptyRow, "M").Value = TextBoxDatePar.Text
    .Cells(emptyRow, "J").Value = TextBoxCostPar.Text
    .Cells(emptyRow, "O").Value = TextBoxAffectCust.Text
    .Cells(emptyRow, "Q").Value = TextBoxCustNonRetail.Text
    .Cells(emptyRow, "P").Value = TextBoxCustRetail.Text
    .Cells(emptyRow, "S").Value = TextBoxOutsourcingImp.Text
    .Cells(emptyRow, "R").Value = TextBoxKeyStatus.Text
    .Cells(emptyRow, "K").Value = TextBoxSchStart.Text
    .Cells(emptyRow, "L").Value = TextBoxSchEnd.Text
    .Cells(emptyRow, "V").Value = TextBoxRagSchedule.Text
    .Cells(emptyRow, "U").Value = TextBoxRagFinancial.Text
    .Cells(emptyRow, "W").Value = TextBoxRagBenefit.Text
    .Cells(emptyRow, "I").Value = TextBoxCost.Text
    .Rows(emptyRow+1).Insert
  End With
  Unload AddProject
End Sub