【问题标题】:Macro Coding in Excel [duplicate]Excel中的宏编码[重复]
【发布时间】:2016-06-17 17:18:52
【问题描述】:

您好,我在 StackOverflow 上找到了这段代码,我想知道如何修改它(请参阅下面的代码截图...)

    Sub TestMacro()

        Dim dblRow As Double, dtDate As Date, strProject As String 
        Dim strFalut As String, strProb As String, strSol As String

        dblRow = InputBox("Input on What Row?")
        dtDate = InputBox("Date", , Date)
        strProject = InputBox("Project #")
        strFalut = InputBox("Fault")
        strProb = InputBox("Problem")
        strSol = InputBox("Solution")

        Range("A" & dblRow).Value = dtDate
        Range("B" & dblRow).Value = strProject
        Range("C" & dblRow).Value = strFalut
        Range("D" & dblRow).Value = strProb
        Range("E" & dblRow).Value = strSol

    End Sub

这是执行我希望它执行的功能的良好开端...但是我想知道如何使用 vLookUp 对其进行修改以搜索下一个空行并开始在那里输入数据而不必手动定义一行,这可能会导致操作员错误,因为这些行变得更多...

【问题讨论】:

  • 学习UserForm的好机会,6个输入框不好。如果您有一个项目、故障、问题、解决方案列表表,您可以使用 ComboBox。日期的日期选择器。

标签: excel vba input vlookup


【解决方案1】:

你可以像这样得到第一个空白行:

Range("A" & Range("A" & Rows.count).end(xlup).row + 1).value = dtDate

显然更改要更新的列的 A 的两个实例。

或者将dblRow = InputBox("Input on What Row?") 更新为此dblRow = range("A" & rows.count).end(xlup).row 并保持其余代码不变。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    相关资源
    最近更新 更多