根据组合框的值将文本框数据发送到工作表中的特定行/单元格

问题描述 投票:1回答:1

我建立了一个用户窗体,用于捕获有关工人完成工作需要多长时间的数据。

我创建了第二个表单来查找参考并输入他/她完成工作的时间。

我可以将所有数据从第一个表单发送到工作表'Tracker',还可以查找'Job Reference'以在第二个用户表单上填充数据。但是,我无法将“结束时间”发送到与“作业参考”标识符相关的行。

我尝试使用与查找空行并以第一种形式插入数据相同的代码,但是它在下一个空行中输入结束时间。

enter image description here

Private Sub CommandButton1_Click()

endTimeTxt.Value = Time

End Sub

Private Sub CommandButton2_Click()

Application.ScreenUpdating = False

    'Defines worksheet and Database Var
Dim findRng As Range
Dim lookup As String
lookup = Trim(Application.InputBox("What ID do you want to find?"))
Set findRng = Range("G5:G1000").Find(what:=lookup)

If Not findRng Is Nothing Then
    Debug.Print "The row to use is: " & findRng.Row
Else
    MsgBox (lookup & "was not found in column A!")
End If

Application.ScreenUpdating = True
End Sub

Private Sub UserForm_Initialize()
Dim xRg As Range
    Set xRg = Worksheets("Lists ").Range("I2:P21")
    Me.jobRefCbo.List = xRg.Columns(1).Value
End Sub

Private Sub jobRefCbo_Change()

    'Formatting Issue
    jobCloseFrm.date2Txt.Value = Format(Range("W1").Value, "dd/mm/yyyy")
        Me.nameTxt.Value = Application.WorksheetFunction.VLookup(CDbl(Me.jobRefCbo.Value), Worksheets("Lists ").Range("I2:P21"), 2, False)
        Me.jobDesc2Txt.Value = Application.WorksheetFunction.VLookup(CDbl(Me.jobRefCbo.Value), Worksheets("Lists ").Range("I2:P21"), 3, False)
        'Me.date2Txt.Value = Application.WorksheetFunction.VLookup(CDbl(Me.jobRefCbo.Value), Worksheets("Lists ").Range("I2:P21"), 4, False)
        Me.month2Txt.Value = Application.WorksheetFunction.VLookup(CDbl(Me.jobRefCbo.Value), Worksheets("Lists ").Range("I2:P21"), 5, False)
        Me.timeOnJobTxt.Value = Application.WorksheetFunction.VLookup(CDbl(Me.jobRefCbo.Value), Worksheets("Lists ").Range("I2:P21"), 6, False)
        Me.StatusTxt.Value = Application.WorksheetFunction.VLookup(CDbl(Me.jobRefCbo.Value), Worksheets("Lists ").Range("I2:P21"), 7, False)
        Me.startTime2Txt.Value = Format(CDate(Application.WorksheetFunction.VLookup(CDbl(Me.jobRefCbo.Value), Worksheets("Lists ").Range("I2:P21"), 8, False)), "hh:mm:ss AM/PM")

End Sub

我当时正在尝试用Google搜索代码,这就是为什么发送Time End的代码没有多大意义。

excel vba userform
1个回答
0
投票

广义上讲,是这样的>

'in click event

Dim findRng As Range

Set findRng = Range("A5:A1000").Find(what:=Me.combobox1.Value) 'insert name of combobox here

If Not findRng Is Nothing Then
    Cells(findRng.Row, 9).Value = Me.textbox1.Value            'insert name of textbox here
End If
© www.soinside.com 2019 - 2024. All rights reserved.