Code is stuck on LastRow formula

Jeffreyxx01

Board Regular
Joined
Oct 23, 2017
Messages
156
Hello guys,

I want to copy data from RawData into RawData2

Taking the data from RawData range A2:CF until it find lastrow ===> then copy this data into RawData2 from range A11
But before pasting the data into RawData2, I want to clear content from A11:CF until last row.

That is pretty much what I need.

Thanks for the help.

Code:
Sub CopyData()

Dim iLastRow As Long
Dim LastRow As Long




With Worksheets("RawData2").Select
[COLOR=#ff0000]LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row[/COLOR]
Range("A11:CF" & LastRow).ClearContents




Sheets("RawData").Select
iLastRow = ActiveSheet.UsedRange.Rows.Count
Sheets("RawData").Range("A2:CF" & LastRow).Copy
End With


Sheets("RawData2").Range("A11").PasteSpecial xlPasteValues
Application.CutCopyMode = False


End Sub

 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Making a few changes to your example you could do it like this:

Code:
Dim iLastRow As Long
Dim LastRow As Long

With Worksheets("RawData2")
    LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If LastRow > 10 Then .Range("A11:CF" & LastRow).ClearContents
    With Sheets("RawData")
        iLastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        .Range("A2:CF" & LastRow).Copy
    End With
    .Range("A11").PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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