paste method of worksheet failed

lucigen

New Member
Joined
Jun 9, 2011
Messages
15
Hey guys, I know this has come up alot before and I've done my best to read all of the information on this byt im still gettin trouble here.

this is a part of the code (as of now) that is in the while loop
xlSht has been defined as a sheet in another workbook
indexing stuff is fine, but sometimes (and it seems random) the paste method fails. I was copying rows before but i read on msdn that caused a problem sometimes, but the switch to a range didn't help. Also I can't use pastespecial because im copying potentially massive quantities of data. I also did all the activateing/selecting combinations I could think of to no avail even though I was pretty certain they wouldn't work.

Code:
        'if statements check to see if the key is in
        If InStr(1, sFilename, key1, vbTextCompare) > 0 Then
            'if its the first one, copy header
            If cT = 0 Then
                xlSht.Range("A1:" & Cells(yT, 26).Address).Copy
            Else 'otherwise copy all but header
                xlSht.Range("A2:" & Cells(yT, 26).Address).Copy
            End If
            If yT <> 1 Then
                ThisWorkbook.Activate
                'activates and does copy/paste operation
                Sheets(shtindforadd + 4).Activate
                Cells(yV, 1).Select
                ThisWorkbook.ActiveSheet.Paste
                Application.CutCopyMode = False
                'resets yV to bottom with pasted material
                yV = yV + yT - cT
                cT = 1
            End If
                        
        Elseif...

it doesnt seem to hit the same problem at each time, tried clearing memory every iteration but still nothing. its happened to me now on everything from 159 rows to 12700.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
have you tried to step through the code. Sometimes I can see why it fails when I step thru it. Also if it fails and I try it manually (without code) I get a clue.
 
Upvote 0
good point, I forgot to mention the most bizarre part of this whole endeavor. So when it hits I click degbug right, and so theoretically if i ask it to take a step forward it should error. Not so. Debug - F5 - goes right along. This has lead me to believe its either a memory cache thing where its reaching the limit which i tried to fix using cutcopy with no success. Also thought it might be an active workbook/worksheet/range issue but you can see ive worked on that and had no success.

Im baffled
 
Upvote 0
oh sorry, F5 runs it, F8 steps. so basically its error free as soon as you try to move on to later code somehow
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

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