PC Review


Reply
Thread Tools Rate Thread

Can't figure out this PasteSpecial error message

 
 
Ayo
Guest
Posts: n/a
 
      25th Feb 2010
I keep getting this error message "PasteSpecial method of Range class failed"
in the code below at the line: "Selection.PasteSpecial Paste:=xlPasteAll" and
I can't figure out what the problem is.
Any ideas?

For Each c In insiteWS.Range("A" & insiteCurrRow & ":A" & insitelastRow &
"").Cells
If c.Value = marketName And c.Offset(0, 1).Value = NLP Then
insiteWS.Select
insiteWS.Range("A" & insiteCurrRow & ":" & insitelastColumn &
insiteCurrRow).Select
Selection.Copy
marketWS.Select
Range("A" & marketCurrRow).Select
Selection.PasteSpecial Paste:=xlPasteAll
marketCurrRow = marketCurrRow + 1
insiteCurrRow = insiteCurrRow + 1
Else
Exit For
End If
Next c
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      25th Feb 2010
What happens if you do the same steps manually?

Do you get the error?

Maybe you have a worksheet event that fires when you activate/deactivate a
sheet--or when you change selection. Most macros will clear the contents of the
clipboard when they run.

Is the worksheet getting pasted protected?

Does either of the ranges include merged cells?

=======
If it's not one of those, I'd do:

'with your other declarations...
dim RngToCopy as range
Dim DestCell as range

....other code here

with insitews
for each c in .range("A" & insitecurrrow & ":A" & insitelastrow).cells
if c.value = marketname _
and c.offset(0,1).value = nlp then
set rngtocopy = .range("a" & insitecurrrow _
& ":" & insitelastcolumn & insitecurrrow)

with marketws
set destcell = .range("A" & marketcurrrow)
end with

rngtocopy.copy
destcell.pastespecial Paste:=xlPasteAll

marketCurrRow = marketCurrRow + 1
insiteCurrRow = insiteCurrRow + 1
Else
Exit For
End If
End with

(Untested, uncompiled. Watch for typos.)


Ayo wrote:
>
> I keep getting this error message "PasteSpecial method of Range class failed"
> in the code below at the line: "Selection.PasteSpecial Paste:=xlPasteAll" and
> I can't figure out what the problem is.
> Any ideas?
>
> For Each c In insiteWS.Range("A" & insiteCurrRow & ":A" & insitelastRow &
> "").Cells
> If c.Value = marketName And c.Offset(0, 1).Value = NLP Then
> insiteWS.Select
> insiteWS.Range("A" & insiteCurrRow & ":" & insitelastColumn &
> insiteCurrRow).Select
> Selection.Copy
> marketWS.Select
> Range("A" & marketCurrRow).Select
> Selection.PasteSpecial Paste:=xlPasteAll
> marketCurrRow = marketCurrRow + 1
> insiteCurrRow = insiteCurrRow + 1
> Else
> Exit For
> End If
> Next c


--

Dave Peterson
 
Reply With Quote
 
Ayo
Guest
Posts: n/a
 
      25th Feb 2010
I have a activate event and change event in the marketWS worksheet. Could
that be why? And how do I fix the problem?
Thanks.

"Dave Peterson" wrote:

> What happens if you do the same steps manually?
>
> Do you get the error?
>
> Maybe you have a worksheet event that fires when you activate/deactivate a
> sheet--or when you change selection. Most macros will clear the contents of the
> clipboard when they run.
>
> Is the worksheet getting pasted protected?
>
> Does either of the ranges include merged cells?
>
> =======
> If it's not one of those, I'd do:
>
> 'with your other declarations...
> dim RngToCopy as range
> Dim DestCell as range
>
> ....other code here
>
> with insitews
> for each c in .range("A" & insitecurrrow & ":A" & insitelastrow).cells
> if c.value = marketname _
> and c.offset(0,1).value = nlp then
> set rngtocopy = .range("a" & insitecurrrow _
> & ":" & insitelastcolumn & insitecurrrow)
>
> with marketws
> set destcell = .range("A" & marketcurrrow)
> end with
>
> rngtocopy.copy
> destcell.pastespecial Paste:=xlPasteAll
>
> marketCurrRow = marketCurrRow + 1
> insiteCurrRow = insiteCurrRow + 1
> Else
> Exit For
> End If
> End with
>
> (Untested, uncompiled. Watch for typos.)
>
>
> Ayo wrote:
> >
> > I keep getting this error message "PasteSpecial method of Range class failed"
> > in the code below at the line: "Selection.PasteSpecial Paste:=xlPasteAll" and
> > I can't figure out what the problem is.
> > Any ideas?
> >
> > For Each c In insiteWS.Range("A" & insiteCurrRow & ":A" & insitelastRow &
> > "").Cells
> > If c.Value = marketName And c.Offset(0, 1).Value = NLP Then
> > insiteWS.Select
> > insiteWS.Range("A" & insiteCurrRow & ":" & insitelastColumn &
> > insiteCurrRow).Select
> > Selection.Copy
> > marketWS.Select
> > Range("A" & marketCurrRow).Select
> > Selection.PasteSpecial Paste:=xlPasteAll
> > marketCurrRow = marketCurrRow + 1
> > insiteCurrRow = insiteCurrRow + 1
> > Else
> > Exit For
> > End If
> > Next c

>
> --
>
> Dave Peterson
> .
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Feb 2010
I would bet money on it--well, if those macros are non-trivial.

I'd try the code that I suggested in the earlier post. No selecting, no
activating.

But if you want to stop the worksheet_change event on the marketws to not fire,
you can stop it this way:

application.enableevents = false
rngtocopy.copy
destcell.pastespecial Paste:=xlPasteAll
application.enableevents = true

Ayo wrote:
>
> I have a activate event and change event in the marketWS worksheet. Could
> that be why? And how do I fix the problem?
> Thanks.
>
> "Dave Peterson" wrote:
>
> > What happens if you do the same steps manually?
> >
> > Do you get the error?
> >
> > Maybe you have a worksheet event that fires when you activate/deactivate a
> > sheet--or when you change selection. Most macros will clear the contents of the
> > clipboard when they run.
> >
> > Is the worksheet getting pasted protected?
> >
> > Does either of the ranges include merged cells?
> >
> > =======
> > If it's not one of those, I'd do:
> >
> > 'with your other declarations...
> > dim RngToCopy as range
> > Dim DestCell as range
> >
> > ....other code here
> >
> > with insitews
> > for each c in .range("A" & insitecurrrow & ":A" & insitelastrow).cells
> > if c.value = marketname _
> > and c.offset(0,1).value = nlp then
> > set rngtocopy = .range("a" & insitecurrrow _
> > & ":" & insitelastcolumn & insitecurrrow)
> >
> > with marketws
> > set destcell = .range("A" & marketcurrrow)
> > end with
> >
> > rngtocopy.copy
> > destcell.pastespecial Paste:=xlPasteAll
> >
> > marketCurrRow = marketCurrRow + 1
> > insiteCurrRow = insiteCurrRow + 1
> > Else
> > Exit For
> > End If
> > End with
> >
> > (Untested, uncompiled. Watch for typos.)
> >
> >
> > Ayo wrote:
> > >
> > > I keep getting this error message "PasteSpecial method of Range class failed"
> > > in the code below at the line: "Selection.PasteSpecial Paste:=xlPasteAll" and
> > > I can't figure out what the problem is.
> > > Any ideas?
> > >
> > > For Each c In insiteWS.Range("A" & insiteCurrRow & ":A" & insitelastRow &
> > > "").Cells
> > > If c.Value = marketName And c.Offset(0, 1).Value = NLP Then
> > > insiteWS.Select
> > > insiteWS.Range("A" & insiteCurrRow & ":" & insitelastColumn &
> > > insiteCurrRow).Select
> > > Selection.Copy
> > > marketWS.Select
> > > Range("A" & marketCurrRow).Select
> > > Selection.PasteSpecial Paste:=xlPasteAll
> > > marketCurrRow = marketCurrRow + 1
> > > insiteCurrRow = insiteCurrRow + 1
> > > Else
> > > Exit For
> > > End If
> > > Next c

> >
> > --
> >
> > Dave Peterson
> > .
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot figure out the error message Jack Microsoft Access Form Coding 1 30th Dec 2008 10:52 PM
PasteSpecial error message Hennie Neuhoff Microsoft Excel Programming 1 13th Nov 2008 03:50 PM
Can't figure out the error message Frank Situmorang Microsoft Access Database Table Design 1 2nd Jul 2008 03:54 PM
Cannot figure out the Error Message =?Utf-8?B?Q0s=?= Microsoft Access Forms 2 29th Oct 2004 04:48 PM
Error message I can't figure out MatGyver Microsoft Outlook Discussion 1 15th Oct 2003 03:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 AM.