B
bawpie
I've already searched on autofill macros and found bits and pieces that help,
but my lack of understanding of the actual VBA is hampering my success with
this particular macro.
The macro in question is set up to copy and paste data to various
spreadsheets and then add formulas to each sheet depending on what I'm
looking for. I've managed to do this with the macro, but when it comes to
autofilling the formula columns on seperate sheets it's working, but only to
a point.
Using the following formula on sheet A, the macro works. It autofills to
the point in column A on Sheet A in the right column.
Sheets("Sheet A").Select
Range("O2").Select
ActiveCell.Formula = "=NETWORKDAYS(M2,H2,Lookup!$A$2:$A$82)-1"
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("O2").AutoFill _
Destination:=.Range("O2:O" & LastRow)
End With
However, when the macro moves onto sheet 2, it is still using the reference
from sheet A (i.e. on sheet A formula is dragged down to row 371 which is
correct, but on sheet B it's still pulling to row 371 which is too long).
Sheets("Sheet B").Select
Range("O2").Select
Application.CutCopyMode = False
ActiveCell.Formula = "=VLOOKUP(A2,Initials!A:H,8,FALSE)"
Dim LastRow2 As Long
With ActiveSheet
LastRow2 = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("O2").AutoFill _
Destination:=.Range("O2:O" & LastRow)
End With
There's a third sheet that has the same behaviour as sheet B. I'm guessing
it's something to do with how I'm defining the 'Lastrow' but any help on the
matter would be much appreciated!
but my lack of understanding of the actual VBA is hampering my success with
this particular macro.
The macro in question is set up to copy and paste data to various
spreadsheets and then add formulas to each sheet depending on what I'm
looking for. I've managed to do this with the macro, but when it comes to
autofilling the formula columns on seperate sheets it's working, but only to
a point.
Using the following formula on sheet A, the macro works. It autofills to
the point in column A on Sheet A in the right column.
Sheets("Sheet A").Select
Range("O2").Select
ActiveCell.Formula = "=NETWORKDAYS(M2,H2,Lookup!$A$2:$A$82)-1"
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("O2").AutoFill _
Destination:=.Range("O2:O" & LastRow)
End With
However, when the macro moves onto sheet 2, it is still using the reference
from sheet A (i.e. on sheet A formula is dragged down to row 371 which is
correct, but on sheet B it's still pulling to row 371 which is too long).
Sheets("Sheet B").Select
Range("O2").Select
Application.CutCopyMode = False
ActiveCell.Formula = "=VLOOKUP(A2,Initials!A:H,8,FALSE)"
Dim LastRow2 As Long
With ActiveSheet
LastRow2 = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("O2").AutoFill _
Destination:=.Range("O2:O" & LastRow)
End With
There's a third sheet that has the same behaviour as sheet B. I'm guessing
it's something to do with how I'm defining the 'Lastrow' but any help on the
matter would be much appreciated!