gpt4 book ai didi

vba - 给定字符串查找单元格的列

转载 作者:行者123 更新时间:2023-12-04 21:16:25 26 4
gpt4 key购买 nike

我正在尝试查找包含字符串“状态”的单元格的列。该单元格位于另一个名为“报告”的工作表中,我不知道该单元格在哪里;我只知道它包含什么。我只需要知道单元格所在的列。我将如何执行此操作(在 VBA 中)?任何帮助将不胜感激!到目前为止,我的代码如下:

Sheets("Report").Select
Dim header_cell As Variant
Set header_cell = Cells.Find(what:="Status")

最佳答案

我建议您避免激活工作表以使用它。

    Dim header_cell As Range
With Sheets("Report")
'this searches just row 1
'Set header_cell = .Rows(1).Find(what:="Status", lookat:=xlWhole, MatchCase:=False, searchformat:=False)
'this searches the whole worksheet
Set header_cell = .Cells.Find(what:="Status", lookat:=xlWhole, MatchCase:=False, searchformat:=False)
Debug.Print header_cell; "Column: " & header_cell.Column
Debug.Print header_cell; "Address: " & header_cell.Address(0, 0, ReferenceStyle:=xlA1, external:=True)
End With

How to avoid using Select in Excel VBA macros有关摆脱依赖选择和激活的方法的更多信息。

关于vba - 给定字符串查找单元格的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30267999/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com