finalrow = Cells(Rows.Count, 1).End(x1Up).Row Getting a error that I can't get past

DarrenF

Board Regular
Joined
Jun 9, 2014
Messages
90
I'm using the below VBA to return information from 2000's rows of data and I keep getting an error when using the line finalrow = Cells(Rows.Count, 1).End(x1Up).Row. Any help would be appreciated!


Sub finddata()

Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim agentname As String
Dim finalrow As Integer
Dim i As Integer

Set datasheet = Sheet2
Set reportsheet = Sheet1
agentname = reportsheet.Range("C1").Value

reportsheet.Range("B4:W13").ClearContents

datasheet.Select
finalrow = Cells(Rows.Count, 1).End(x1Up).Row

For i = 2 To finalrow
If Cells(i, 1) = agentname Then
Range(Cells(i, 3), Cells(i, 24)).Copy
reportsheet.Select
Range("B100").End(x1Up).Offset(1, 0).PasteSpecial x1PasteFormulasAndNumberFormats
datasheet.Select
End If

Next I


reportsheet.Select

Range("C1").Select
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
It should be xlUp, not x1Up (a lower case letter L, not the number 1).
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

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