Excel 中带有下拉菜单的列

发布于 2024-12-13 06:58:10 字数 275 浏览 2 评论 0原文

我是一名业余 VBA 用户,需要一些指导...

我在 Excel 中有两个工作表(1)账单,(2)合同。帐单表有一列包含带有帐单说明的下拉菜单。 B 列和 B 列C 是开始 &停止时间。 D 列是位于合同表中的“成本”,与账单说明相关联。根据帐单说明,D 列(帐单表)中会填充成本。

我需要公式(如果可能)或 VBA 代码的帮助,如果用户从下拉列表中输入超出合同的内容,“合同描述”将替换初始下拉条目,超额描述将自动删除向下到下面的行并自动填充开始和结束位置同一行的停止时间。任何帮助将不胜感激。

I'm an amateur VBA user and need some guidance...

I have two worksheets in Excel (1) Billing, (2) Contract. Billing Sheet has a column with a drop-down menu with billing descriptions. Columns B & C are start & stop times. Column D are 'cost' that located on in the Contract Sheet and are associated with the billing description. Depending on the billing description, the cost in Column D (Billing Sheet) populates.

I need help with either a formula (if possible) or VBA code that if the user inputs something from the drop-down that exceeds the contract, the 'contract decription' will replace the initial drop-down entry and the overage desciption will automatically drop down to the row beneath as well as automatically populate the start & stop times in that same row. Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜中书 2024-12-20 06:58:10

像这样的东西(位于工作表代码模块中)

Private Sub Worksheet_Change(ByVal Target As Range)

    Const VAL_TRIPLE As String = "Triple"
    Const VAL_DOUBLE As String = "Double"
    Dim rng As Range, cost

    On Error GoTo haveError

    Set rng = Target.Cells(1)

    If rng.Column = 1 And rng.Row > 1 Then

        DoEvents 'run the cost lookup...
        cost = rng.EntireRow.Cells(4).Value

        With rng
            If .Value = VAL_DOUBLE Or .Value = VAL_TRIPLE Then
                Application.EnableEvents = False

                .Offset(1, 0).Insert
                .Offset(1, 0).Value = .Value
                If IsNumeric(cost) Then
                   .Offset(1, 3).Value = cost * IIf(.Value = VAL_TRIPLE, 2, 1)
                End If
                .Value = "replacement" 'how to know what goes here?
                .Offset(1, 1).Value = .Offset(0, 1).Value
                .Offset(1, 2).Value = .Offset(0, 2).Value

                Application.EnableEvents = True
            End If
        End With
    End If

    Exit Sub

haveError:
    Application.EnableEvents = True

End Sub

Something like this (goes in the Worksheet code module)

Private Sub Worksheet_Change(ByVal Target As Range)

    Const VAL_TRIPLE As String = "Triple"
    Const VAL_DOUBLE As String = "Double"
    Dim rng As Range, cost

    On Error GoTo haveError

    Set rng = Target.Cells(1)

    If rng.Column = 1 And rng.Row > 1 Then

        DoEvents 'run the cost lookup...
        cost = rng.EntireRow.Cells(4).Value

        With rng
            If .Value = VAL_DOUBLE Or .Value = VAL_TRIPLE Then
                Application.EnableEvents = False

                .Offset(1, 0).Insert
                .Offset(1, 0).Value = .Value
                If IsNumeric(cost) Then
                   .Offset(1, 3).Value = cost * IIf(.Value = VAL_TRIPLE, 2, 1)
                End If
                .Value = "replacement" 'how to know what goes here?
                .Offset(1, 1).Value = .Offset(0, 1).Value
                .Offset(1, 2).Value = .Offset(0, 2).Value

                Application.EnableEvents = True
            End If
        End With
    End If

    Exit Sub

haveError:
    Application.EnableEvents = True

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文