0

I'm trying to set the first and last rows of a For loop. The 'controlCell' and 'firstrow' work as intended but I can't get the 'lastrow' piece to work.

The code I'm using is this:

    Dim k As Integer
    Dim controlCell As Integer
    controlCell = Range("F9").Value
    Dim firstrow As Integer
        With Columns("A")
            .Find(what:="*", after:=.Cells(1, 1), LookIn:=xlFormulas).Activate
            firstrow = ActiveCell.Row
        End With
    Dim lastrow As Integer
        With Columns("E")
            .Find(what:=.Range(controlCell), after:=.Cells(18, 5), LookIn:=xlValues).Activate
            lastrow = ActiveCell.Row
        End With
        For k = firstrow To lastrow

For example, there will be a value of 22 in the controlCell, there are dates in Column A and in column E from row 18, there will be numbers 1 to another number. I need to call out where 22 is in this column and run the For loop between the firstrow and lastrow. The number in the controlCell is not always 22.

Running the code as is returns a Compile error: Syntax error on the line

.Find(what:=.Range(controlCell), after:=.Cells(18, 5), LookIn:=xlValues).Activate

Thanks in advance.

Keith K
  • 129
  • 9

0 Answers0