在设定的区域内查找/查找
当我将“lFundcolumn”中的“Activesheet.cells”replace为“rnMonths”时,我得到“运行时错误13”。 如果有人能够解释我在这里做错了,我会很感激。
简而言之 – 我想在一行中find一个值,并复制该列和右侧的列。 以下是查找错误的第一列的代码。
Sub Roll_period() Dim sMonth As String Dim rnMonths As Range Dim lFundcolumn As Long Dim rnRngtocopy As Range sMonth = ActiveSheet.Cells(3, 1).Value Set rnMonths = ActiveSheet.Rows(4) lFundcolumn = rnMonths.Find(What:=sMonth, after:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole, searchorder:=xlByColumns).Column
…你做的一切都是正确的,你的问题是after:=ActiveCell
在你的Find
语句,这可能也可能不指向正确的地方看… after:=ActiveCell
…
将其更改为:
after:=rnMonths.Cells(1, 1)
这看起来像:
lFundcolumn = rnMonths.Find(What:=sMonth, after:=rnMonths.Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, searchorder:=xlByColumns).Column
希望这个把戏!