查找单元格中的值的宏然后将“x”输入到另一个单元格中

时间:2015-10-26 20:39:44

标签: excel vba formula lookup

有人可以告诉我宏代码会查找我在单元格中键入的值。

然后在单元格的同一行输入字母x,但在右边的4列中输入?然后保存。

想法是在单元格中键入文本按一个按钮然后查找它然后将x添加到另一个单元格并保存结束子。??

Sub MakeTheChanges()
Dim BayControl As Worksheet Set BayControl = ThisWorkbook.Sheets("Bay control")
BayControl.Range("A" & BayControl.Range("M1").Value + 1) = "BAY CLEAR"
BayControl.Range("C" & BayControl.Range("M1").Value + 1) = ""
BayControl.Range("D" & BayControl.Range("M1").Value + 1) = "N/A"
BayControl.Range("M1") = ""
End Sub

1 个答案:

答案 0 :(得分:0)

请参阅下文,了解我对您所寻找的内容的解释:

Sub EnterThexA()

    Dim Sunday As Worksheet, xRange As Range

    ' If E1 contains an error, just give up.
    If IsError(Range("E1")) Then Exit Sub

    ' If E1 doesn't have any value, just give up.
    If Len(Range("E1").Value) = 0 Then Exit Sub

    Set Sunday = ThisWorkbook.Sheets("Sunday")

    ' See if you can find whatever is in range "E1" in column A, if so, set xRange to that Cell
    Set xRange = Columns("A:A").Find(What:=Range("E1").Value, LookIn:=xlValues, Lookat:=xlWhole)

    ' If you in fact found something
    If Not xRange Is Nothing then
        ' You want the x in column E, which is 4 places to the right.
        Set xRange = xRange.Offset(0, 4)
        xRange.Value = "x"
    End If

    ' Set certain variables to nothing (just good form, not really necessary)
    Set Sunday = Nothing: Set xRange = Nothing

End Sub