找到一个值,然后使用下拉列表中的“是”或“否”修改右侧的单元格4列

时间:2019-05-03 22:05:28

标签: excel vba

我想打开一个消息框并找到位于sheet 2, column B上的报价单号。如果找到,消息框将要求更新报价列的状态,该列位于F列右侧的4个单元格中。

我从另一个网站上获取了另一个代码/按钮的代码。当我尝试将其用于此应用程序时,它不会跟踪并修改F列上的最后一个条目。

我认为需要对行Soldlr = Ws.Range("F" & Rows.Count).End(xlUp).Row进行修改,以将其更改为在消息框能够找到的任何引用号右边的4个单元格中更改信息。

Option Explicit

Sub UpdateEntry()
Dim ws As Worksheet
Dim strSearch As String
Dim aCell As Range
Dim Sold As String, Soldlr As Long

Set ws = Sheets("Data Entry")

With ws
    strSearch = InputBox("Enter Quote Number To Update", "Update Quote Entry")
    Set aCell = .Columns(2).Find(What:=strSearch, LookIn:=xlValues, _
                                 LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                 MatchCase:=False, SearchFormat:=False)

    If Not aCell Is Nothing Then

        Sold = InputBox("Was This Quote Sold?", "Sales Entry", "Yes or No")
        aCell.Offset(0, 4) = Sold
        MsgBox "Quote Number " & strSearch & " Has Been Modified"

    Else

        MsgBox "Quote Number " & strSearch & " Not Found. Try Again"
    End If

    Exit Sub
End With
End Sub

我希望按下一个按钮,然后出现一个消息框。那个盒子会要求报价。输入报价编号后,它将查找该报价编号并询问“是否已出售报价编号'输入的报价编号'?”下拉列表中只有两个可能的选择(“是”和“否”)。无论选择什么答案,都会覆盖找到的报价编号右侧4个空格的单元格。

1 个答案:

答案 0 :(得分:0)

我无法查看修改。我想我不在那个水平上。 :(

Option Explicit

Sub UpdateEntry()
Dim ws As Worksheet
Dim strSearch As String
Dim aCell As Range
Dim Sold As String, Soldlr As Long

Set ws = Sheets("Data Entry")

With ws
    strSearch = InputBox("Enter Quote Number To Update", "Update Quote Entry")
    Set aCell = .Columns(2).Find(What:=strSearch, LookIn:=xlValues, _
                                 LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                 MatchCase:=False, SearchFormat:=False)

    If Not aCell Is Nothing Then

        Sold = InputBox("Was This Quote Sold?", "Sales Entry", "Yes or No")
        aCell.Offset(0, 4) = Sold
        MsgBox "Quote Number " & strSearch & " Has Been Modified"

    Else

        MsgBox "Quote Number " & strSearch & " Not Found. Try Again"
    End If

    Exit Sub
End With
End Sub