左功能VBA

时间:2017-04-18 12:48:12

标签: vba excel-vba search formula userform

大家好,愿意提供帮助。

我似乎在VBA中遇到左侧功能问题。我希望使用参考编号进行搜索,然后userform将获取存储在表中的数据。在userform的1部分中,我有4个文本框,用于浏览1个单元格的不同部分。麻烦的是我得到了" FO"对于我的代码中实际查看fo的每个引用的答案,请参见下文。

    Private Sub Find_Click()

    Dim searchRange As Range
    Dim foundCell As Range
    Dim mysearch As String

    mysearch = Me.Search.Value

    With ThisWorkbook.Sheets("Master Data")
        Set searchRange = .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
    End With

    Set foundCell = searchRange.Find(what:=mysearch, Lookat:=xlWhole, MatchCase:=False, SearchFormat:=False)
    If Not foundCell Is Nothing Then
        Me.BDM.Value = foundCell.Offset(0, 6).Value
        Me.Mrch.Value = foundCell.Offset(0, 7).Value
        Me.EUs.Value = foundCell.Offset(0, 8).Value
        Me.Pr.Value = foundCell.Offset(0, 10).Value
        Me.Qty.Value = foundCell.Offset(0, 11).Value
        Me.RsnCd.Value = foundCell.Offset(0, 12).Value
        Me.ReOrCd.Value = foundCell.Offset(0, 13).Value
        Me.Tot.Value = foundCell.Offset(0, 5).Value
        Me.V.Value = Me.Total.Value / 1.2
        Me.VT.Value = Me.Total.Value - Me.Value.Value
        Me.Req.Value = foundCell.Offset(0, 17).Value
        Me.Appl.Value = foundCell.Offset(0, 18).Value
        Me.Line1.Value = foundCell.Offset(0, 19).Value
        Me.Line2.Value = foundCell.Offset(0, 20).Value
        Me.Ci.Value = foundCell.Offset(0, 21).Value
        Me.Poe.Value = foundCell.Offset(0, 22).Value
        Me.SC1.Value = Left(foundCell.Offset(0, 23).Value, 2)
'this is where in code I am receiving fo from the foundcell everytime       
    Else
         MsgBox "ID does not exist."
    End If

    End Sub

我一直认为vba中的左侧与excel相同,例如left(a2, 2)

1 个答案:

答案 0 :(得分:0)

不确定原因,但只是重新启动excel解决了问题,代码没有问题