Last Row Error (1 Viewer)

jalopez453

Registered User.
Local time
Today, 07:38
Joined
Oct 11, 2016
Messages
18
I am trying to auto-fill tow formulas into two columns to the last row on my report. Every things goes thru smoothly until I get to the LastRow formula. I keep getting an error and I don't understand why.

Code:
Dim xlApp As Object
Dim lRow1 As Long
Set xlApp = CreateObject("Excel.Application")

With xlApp
    .Visible = True
    .Workbooks.Open Filename
    'Sheet1
    .Sheets("Sheet1").Select
    .Range("A10").Select
    .ActiveCell.CopyFromRecordset rstCHR

        strFormulas(1) = "=SUMIF(Charity_Line20!$A:$A,E10,Charity_Line20!$D:$D)"
        strFormulas(2) = "=SUMIF(Charity_Line22!$A:$A,E10,Charity_Line22!$G:$G)"
            lRow1 = .Sheets("Sheet1").Cells(.Rows.Count, "U").End(xlUp).Row
            
        .Range("V10:W" & lRow1).AutoFill = strFormulas

If anyone is able to help me, or see where I am coding it wrong, that would be so helpful. My issues is the lRow1
 

June7

AWF VIP
Local time
Today, 06:38
Joined
Mar 9, 2014
Messages
5,425
Is the error message "Unable to set the AutoFill property of the Range class"?
 
Last edited:

jalopez453

Registered User.
Local time
Today, 07:38
Joined
Oct 11, 2016
Messages
18
Run-time error '1004'
Application-defined or object-defined error


I want to copy down the formulas from Row 10 to the last row, and I keep getting this error for the lastrow code.
 

June7

AWF VIP
Local time
Today, 06:38
Joined
Mar 9, 2014
Messages
5,425
Which line throws error? I don't get that error. I get the one I asked about.

AutoFill is taking content of cell(s) and copying to other cells. The source cell(s) must be included in reference. This simple example worked for me.
Code:
With xlApp
    .Visible = True
    .Workbooks.Open Filename
    .Sheets("Sheet1").Select
    .Range("A10").CopyFromRecordset rs
    lRow1 = .Sheets("Sheet1").Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("F10:F" & lRow1).AutoFill Destination:=.Range("F10:J" & lRow1), Type:=xlFillDefault
End With
 

Users who are viewing this thread

Top Bottom