簡體   English   中英

在單元格中查找值的宏然后在另一個單元格中輸入“x”

[英]A macro that looks up a value in a cell then enters a "x" into another cell

有人可以就宏代碼向我提供建議,該代碼將查找我在單元格中鍵入的值。

然后在單元格的同一行但右側 4 列中輸入字母 x ? 然后保存。

想法是在單元格中輸入文本按一個按鈕,然后查找它然后在另一個單元格中添加一個 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

關於我對您可能正在尋找的內容的解釋,請參見下文:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM