Paste Special Method of Range Class Failed

krish42632

New Member
Joined
Sep 17, 2017
Messages
7
kindly solve this issue



my code is


Private Sub Button9_Click()


Sheets("sys").Range("A9142:A20000").Copy


Dim lastrow As Long
lastrow = Range("A9249:A20000").End(xlUp).Row


Sheets("Sheet1").Activate
Cells(lastrow + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
open
open
open
https://drive.google.com/open?id=0BzYVmIR6p1WzbEJqNUdjWjMwdlk

https://drive.google.com/open?id=0BzYVmIR6p1WzM0dTenlXQkRSQVE

Error Screen Shots Attached
 
Upvote 0
Couple of things.
1) this line is not needed, as you have to be on sheet1, in order to click the button
Code:
Sheets("Sheet1").Activate
2) With the data setup in your sample lastrow will return 1. Suggest you change to
Code:
lastrow = Range("A" & Rows.Count).End(xlUp).Row
I suspect that you are getting the error, because lastrow is 1 & row 1 is hidden, due to the filter
 
Upvote 0
Error Screen Shots Attached
Yes, but do you get that error with the sample file that you provided? I don't.

The macro just copies A9249:A20000 from 'sys' (all formulas that return zero but formatted as "-") and pastes those zero value into Sheet1, starting at cell A1. In Sheet 1 column A you see nothing because you have Excel set to not show zero values in that sheet.
 
Upvote 0
@Peter_SSs
Not sure if it's a version thing (I'm using 2013), but I got the error message described, using the sample file.
 
Upvote 0
@Peter_SSs
Not sure if it's a version thing (I'm using 2013), but I got the error message described, using the sample file.
Hi Fluff
Your message prompted me to download the file again and now I do get the error. Comparing both the filter (not filtered in the original sample) and some of the values in column A of 'sys', it appears that the sample file has been replaced since I first downloaded it. :)

I think you are right about the filter issue.

I wonder where the OP is actually trying to paste the data?
 
Upvote 0
I wonder where the OP is actually trying to paste the data?
I'm guessing that it should be below the existing data, otherwise why use "lastrow"?
 
Upvote 0
I'm guessing that it should be below the existing data, otherwise why use "lastrow"?
You may be right, but then Range("A9249:A20000").End(xlUp).Row is an unusual code so I am not sure you can confidently deduce much from the code.
 
Upvote 0
You may be right, but then Range("A9249:A20000").End(xlUp).Row is an unusual code so I am not sure you can confidently deduce much from the code.

That's a very good point.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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