0

When I replace "Activesheet.cells" in the "lFundcolumn" below with "rnMonths" I'm getting a "Run time error 13". I would be grateful if someone could explain what I'm doing wrong here please.

In short - I want to find a value within a row and copy that column and the column to the right of it. Below is the code for locating the first column which is erroring.

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
4

1 回答 1

4

...您所做的一切都是正确的,您的问题after:=ActiveCell在您的Find陈述中,这可能会或可能不会指向正确的地方查看...

将其更改为:

after:=rnMonths.Cells(1, 1)

看起来像:

lFundcolumn = rnMonths.Find(What:=sMonth, after:=rnMonths.Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, searchorder:=xlByColumns).Column

希望能解决问题!!

于 2013-03-25T14:21:23.023 回答