Consulting

Results 1 to 2 of 2

Thread: VBA to copy / autofill data, where am i going wrong?

  1. #1

    VBA to copy / autofill data, where am i going wrong?

    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

  2. #2
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    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.
    Remember: it is the second mouse that gets the cheese.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •