range find not working

RuthandAndy

New Member
Joined
Jul 18, 2011
Messages
27
I can't get the following code to work for Find. The LastRow remains empty and x1ByRows and x1Previous also show empty?

'Activate the Production Plan workbook, find the empty row and paste data

ppwb.Activate
Sheets("Production Status").Select

'Find the last row
Dim LastRow
Dim DataRow
Dim ws As Worksheet
Set ws = ActiveSheet

LastRow = ws.Cells.Find(What:="*", _
SearchOrder:=x1ByRows, _
SearchDirection:=x1Previous).Row
DataRow = LastRow + 1
Rows("0:0").Offset(DataRow, 0).Select

'Store the data
Selection.Paste
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
For each of the constants assigned to SearchOrder and SearchDirection, the first two characters are xl (ex-el), not x1 (ex-one) as you typed. You might also want to specify a value for the LookIn argument (xlValues to find the last row with a value displayed in it, xlFormulas to display the last used row even if that row contains a formula displaying the empty string).
 
Upvote 0
Code:
    'Find the last row
    Dim DataRow As Long
    
    With Sheets("Production Status")
        DataRow = .Cells.Find(What:="*", _
                              LookIn:=xlFormulas, _
                              SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious).Row + 1
        'Store the data
        .Rows(DataRow).Paste
    End With
 
Upvote 0
Rick, Thank you. I had copied this code from elsewhere and didn't really understand it. Didn't even notice the 1 instead of l in the names. No wonder it didn't work!
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,521
Members
452,923
Latest member
JackiG

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