Find Last row for Autofill macro

iricketts

New Member
Joined
Aug 26, 2015
Messages
1
I pull a report that grades answers for customers and the number of customers changes every day. I currently have the macro run to row 5000, but I want it to stop on the last row.

It has been a long time since my excel class and i'm in over my head. Sorry if my code looks *** backwards.

'Insert the grading formula and convert to hardcoded text
Dim LastRowColX As Integer
LastRowColX = Range("X65536").End(xlUp).Row
Range("Z3").Select
ActiveCell.Formula = "=SUM(IF(H3=$H$2,1,0),IF(I3=$I$2,1,0),IF(J3=$J$2,1,0),IF(K3=$K$2,1,0),IF(L3=$L$2,1,0),IF(M3=$M$2,1,0),IF(N3=$N$2,1,0),IF(O3=$O$2,1,0),IF(P3=$P$2,1,0),IF(Q3=$Q$2,1,0),IF(R3=$R$2,1,0),IF(S3=$S$2,1,0),IF(T3=$T$2,1,0),IF(U3=$U$2,1,0),IF(V3=$V$2,1,0),IF(W3=$W$2,1,0),IF(X3=$X$2,1,0),IF(Y3=$Y$2,1,0))/COUNTA($H$2:$Y$2)"
Range("Z3").Select
Range("Z3").AutoFill Destination:=Range("Z3:Z" & LastRowColX)
End Sub

Any help is appreciated.

Thanks.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Welcome to the Board!

Using Cells(Rows.Count... will take any version of Excel into account:

Code:
    'Insert the grading formula and convert to hardcoded text
     Dim LastRowColX As Integer
     LastRowColX = Cells(Rows.Count, "X").End(xlUp).Row
     
     With Range("Z3")
        .Formula = "=SUM(IF(H3=$H$2,1,0),IF(I3=$I$2,1,0),IF(J3=$J$2,1,0),IF(K3=$K$2,1,0),IF(L3=$L$2,1,0),IF(M3=$M$2,1,0),IF(N3=$N$2,1,0),IF( O3=$O$2,1,0),IF(P3=$P$2,1,0),IF(Q3=$Q$2,1,0),IF(R3=$R$2,1,0),IF(S3=$S$2,1,0),IF(T3=$T$2,1,0),IF(U3=$U$2,1,0),IF(V3=$V$2, 1,0),IF(W3=$W$2,1,0),IF(X3=$X$2,1,0),IF(Y3=$Y$2,1,0))/COUNTA($H$2:$Y$2)"
        .AutoFill Destination:=Range("Z3:Z" & LastRowColX)
    End With

HTH,
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,373
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top