我正在构建一个宏,该宏需要根据一列中的值查找一行,然后在该行中查找数据的开头,然后剪切该信息并将其粘贴到另一张纸上。我遇到了第一个障碍,因为尽管我可以让我的数组遍历该列并找到该值的实例,但是我似乎无法再获取该值的单元格引用。
我尝试使用Range.Address函数,但是这使我收到了运行时错误424对象所需的错误。我不确定如何获得地址。代码已在数组中找到该值,因此它必须知道该值的存储位置。这是我到目前为止所拥有的
frame = tk.Frame(root, bg='#000000', bd=0)
frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')
entry = tk.Entry(frame, font=60, relief='flat')
entry.place(relwidth=0.65, relheight=1)
button = tk.Button(frame, text="Run", relief='flat', font=40, command=lambda: get_weather(entry.get()))
button.place(relx=0.7, relheight=1, relwidth=0.3)
因此,除了尝试获取引用时出现错误外,数组循环还可以完美地工作。一旦循环在数组中找到一个表示“ Completed。”的单元格,那么该如何获取该单元格的引用作为字符串?
答案 0 :(得分:2)
如BigBen所述,您可以使用Match()
:
Dim m
With Range("S2:S10")
m = Application.Match("Completed.",.cells, 0)
If Not IsError(m) Then Range("A1").value = .Cells(m).Address
End With
或Find()
:
Dim f As Range
Set f = Range("S2:S10").Find("Completed.", lookat:=xlWhole)
If Not f Is Nothing Then Range("A1").value = f.Address