Code does not work, copy and paste data from a sheet to another

Jeffreyxx01

Board Regular
Joined
Oct 23, 2017
Messages
156
Hi guys, I got some problems
Can someone help on my code, it highlight the lastrow in yellow.

Thanks.

Code:
Sub copydata()
Dim LastRow As Long


Sheets("Datadump").Range("E:G,S:S,AW:AW,AY:AY,BE:BE,CC:CC,CF:CV").Copy
With Worksheets("Clean")
LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    .Range("A1:Y" & LastRow).ClearContents
    .Range("A1").PasteSpecial xlPasteValues
End With


End Sub
 
Last edited:
If I put the with statement
I have the red line highlighted.

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
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Jeffrey. I think it would be best to tell us what your wanting to do.

Using With is something new in your code.

Tell us your what you want to do in total and lets see if we can sort this out.
 
Upvote 0
Well 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.
 
Upvote 0
When we go back and look at your original question in post 1.

And now see what your asking for is this all the same question or has your original question changed?
 
Upvote 0
In post 1 you asked a question and received a answer you said worked.
Then later you asked a different question

I believe you should make a completely new posting with you new question.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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