VBA代码search行标题,并select该标题下的整个范围

我非常新的VBA,我试图自动化我的一些日常任务。 一个我想自动化的任务需要我“search”一个指定的头,然后select整个数据列。 然后,我会将该范围粘贴到另一个电子表格中。

Tamcolumn = Cells.Find(what:="plan_tamaward", after:="a1", searchdirection:=xlPrevious, searchorder:=xlBycolumn, lookat:=xlPart).Column

我发现这一点代码是有帮助的,当我定义整个列,问题是我不能定义列标题,并定义下面的范围没有“select”的数据 – 我知道是一个大不,不。

我希望这是有道理的。

提前致谢。

您可以将以下方法合并到代码中

 Dim Col As Long, LastRow As Long Dim Rng As Range If Application.CountIf(Rows(1), "plan_tamaward*") > 0 Then Col = Application.Match("plan_tamaward*", Rows(1), 0) LastRow = Cells(Rows.Count, Col).End(xlUp).Row Set Rng = Range(Cells(2, Col), Cells(LastRow, Col)) End If If Not Rng Is Nothing Then MsgBox Rng.Address 'do whatever you want to do with this range here Else MsgBox "The column named like plan_tamaward* was not found in Row1.", vbExclamation, "Column Not Found!" Exit Sub End If