PDA

View Full Version : VBA to copy / autofill data, where am i going wrong?



plasteredric
03-02-2018, 08:54 AM
I have the following code


Sub DAILY_FORMULA_AUTOFILL()


Dim Found As Range


With ActiveSheet ' do everything on the active sheet from here on
Set Found = .Range("A:A").Find("***X", lookat:=xlWhole)


If Found Is Nothing Then
MsgBox "Table Start Point Not Found", 0, "Check Error"

Exit Sub

End If

FirstDataRow = Found.Row + 1
LastRow = .Cells(Rows.Count, "G").End(xlUp).Row ' This finds the last cell with data in it in column G on active sheet

Range("DAILY_FORMULA_RANGE_A").Copy Range("Y416:Y" & LastRow)

End With

End Sub




This works as is, but I was trying to use the 'found' and 'firstdatarow' rather than Y416:Y as a precaution, should i add additional rows / columns in the future. The range of Cells i am autofilling down is Y416:AB416 .

Any ideas for how i can do this? also from what i've read where i have 'LastRow' this should be the bottom rightmost cell of the destination range, in the example this would be AB545. Will having 'LastRow' cause any issues?

Thanks

werafa
03-02-2018, 04:23 PM
the lastrow method you have chosen is one of the better methods.

You don't have to limit it to a specific column if you don't want to.
I typically use this method to define a data range as it can handle blank rows in the data field.

You might need to research it if you have hidden or filtered rows in the data field.