在Userform中,我可以使用什么VBA编码来查找基于行的单元格&;列内容,然后更新该单元格?

在Userform中,我可以使用什么VBA编码来查找基于行的单元格&;列内容,然后更新该单元格?,vba,excel,spreadsheet,userform,Vba,Excel,Spreadsheet,Userform,事实上,我是VBA的完全初学者 我正在尝试创建一个用户表单,该表单将更新一个人在给定日期完成的任务数,如电子表格中所列。我设想Userform有两个botton(隐藏并显示为子例程的条件)。顺便说一下,我正在Mac电脑上工作,我知道在PC机上使用VBA编码会有影响,反之亦然 示例表如下所示: 示例用户表单(a)如下所示: 为了便于讨论,假设我想更新或输入Greg在5月7日(2013/05/07)完成的任务数量 我想让Userform执行如下操作: 输入人员和日期: 然后,点击按钮后,在7号

事实上,我是VBA的完全初学者

我正在尝试创建一个用户表单,该表单将更新一个人在给定日期完成的任务数,如电子表格中所列。我设想Userform有两个botton(隐藏并显示为子例程的条件)。顺便说一下,我正在Mac电脑上工作,我知道在PC机上使用VBA编码会有影响,反之亦然

示例表如下所示:

示例用户表单(a)如下所示:

为了便于讨论,假设我想更新或输入Greg在5月7日(2013/05/07)完成的任务数量

我想让Userform执行如下操作:

输入人员和日期:

然后,点击按钮后,在7号检索Greg的任务数:

现在,我想输入我知道Greg在7日完成了6项任务,我点击第二个按钮(现在可见,第一个按钮隐藏):

以及电子表格中的结果:

我应该在这里输入一些代码,但是我的技能和代码的完整性都很差。但我会把我拥有的东西放进去:

Option Explicit

'Subroutine when clicking the first ("find") button
Private Sub btnfind_Click()
    lbltasks.Vissible = True
    txttasks.Visible = True
    btnupdate.Visible = True
    btnfind.Visible = False

'Defining variables
    Dim pr01 As String
    Dim dt01 As Date
    Dim tsk01 As Integer

'Assigning variables to inputs
    pr01 = txtperson.Text
    dt01 = txtdate.Text
    tsk01 = txttask.Text

'Looking for Name in column "A"
    ' ? ? ?

'Looking for inut Date in row "1"
    ' ? ? ?

'Retrieving the existing number of tasks according to name and date
'and showing number in the 'tasks' text input box in the user form
     ' ? ? ?
End Sub

'Subroutine when clicking the Second ("update") button
Private Sub btnupdate_Click()

'Paste updated Number of tasks in appropriate cells according to name and date
'The new number of tasks should over write what was there previously
    ' ? ? ?

End Sub

提前感谢您的帮助

这应该行得通。请学习并使用Excel中的宏记录功能掌握更多信息:

Option Explicit
Public frmName As Variant 'store row of name
Public frmDate As Variant 'store column of date

'Subroutine when clicking the first ("find") button
Private Sub btnfind_Click()
'Defining variables
    Dim pr01 As String
    Dim dt01 As Date
    Dim tsk01 As Integer

'Assigning variables to inputs
    pr01 = UserForm1.TextBox1.Text
    dt01 = UserForm1.TextBox2.Text
    tsk01 = UserForm1.TextBox3.Text

'Looking for Name in column "A"
    With ThisWorkbook.Worksheets("Sheet4")
        frmName = .Columns("A").Find(pr01).Row
    End With


'Looking for inut Date in row "1"
    With ThisWorkbook.Worksheets("Sheet4")
        frmDate = .Rows(1).Find(CDate(dt01)).Column
    End With

    If frmName Is Nothing Or frmDate Is Nothing Then
        'not found
        Exit Sub
    End If

'Retrieving the existing number of tasks according to name and date
'and showing number in the 'tasks' text input box in the user form
    With ThisWorkbook.Worksheets("Sheet4")
        UserForm1.TextBox3.Text = .Cells(frmName, frmDate)
    End With

End Sub

'Subroutine when clicking the Second ("update") button
Private Sub btnupdate_Click()

'Paste updated Number of tasks in appropriate cells according to name and date
'The new number of tasks should over write what was there previously
    With ThisWorkbook.Worksheets("Sheet4")
        .Cells(frmName, frmDate) = UserForm1.TextBox3.Text
    End With
End Sub

谢谢@glh。不过我还是遇到了问题。当我运行VBA/宏时,我得到一个错误:“运行时错误'91':未设置对象变量或块变量。”当我单击“调试”时,我来到第行:
”使用此工作簿在“1”行中查找输入日期。工作表(“Sheet1”)frmDate=.Rows(1)。Find(CDate(dt01))。列结尾为
我测试了此确定。。。那是三行。还要确保正确设置了变量。有趣的是,它跑过了前一行。