PC Review


Reply
Thread Tools Rate Thread

copy paste to first first open row

 
 
JSnow
Guest
Posts: n/a
 
      5th Mar 2009
I'm trying to copy/special paste a range of information to the first
available row on another sheet called 'Half Payout' or sheet2. When the user
chooses "yes" in any row in column L, the data from columns B:K in that same
row should get special pasted (value only) to the first open row on sheet2.
It doesn't work - the range gets copied and nothing gets special pasted.

Here's my code:
Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo Whoops

If Target.Column = 12 Then 'column L Half Credit
If Target.Row > 5 Then
Dim rw As Integer
rw = Target.Row
Dim halfRange As String
halfRange = "B" & rw & ":K" & rw
If Target.Value = "yes" Then
Range(halfRange).Select 'this grabs the half credit policy
Selection.Copy
Sheet2.Range("B3:B8000").Find(What:="",
After:=Range("B3:B8000").Cells(1), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Select
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, skipblanks:=False, Transpose:=False
Application.CutCopyMode = False 'Clears clipboard.
End If
End If
End If


Whoops:
Application.EnableEvents = True

End Sub

Thanks for any direction.
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      5th Mar 2009
Hi

You miss the sheet reference in the paste special statement.

Here's how I would do it:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim TargetRow As Long
Dim halfRange As String
Dim CopyToRow As Long

Application.EnableEvents = False
'On Error GoTo Whoops

If Target.Column = 12 Then 'column L Half Credit
If Target.Row > 5 Then
TargetRow = Target.Row
halfRange = "B" & TargetRow & ":K" & TargetRow
If Target.Value = "yes" Then ' Case sensitive
If Sheet2.Range("B3") = "" Then
CopyToRow = 3
Else
CopyToRow = Sheet2.Range("B2").End(xlDown).Row + 1 'Assume
headings in B2
End If
Range(halfRange).Copy
Sheet2.Range("B" & CopyToRow).PasteSpecial Paste:=xlPasteValues,
_
Operation:=xlNone, skipblanks:=False, Transpose:=False
Application.CutCopyMode = False 'Clears clipboard.
End If
End If
End If
'Whoops:
Application.EnableEvents = True
End Sub

Regards,
Per

"JSnow" <(E-Mail Removed)> skrev i meddelelsen
news:6562600F-1AA6-40FA-AFCC-(E-Mail Removed)...
> I'm trying to copy/special paste a range of information to the first
> available row on another sheet called 'Half Payout' or sheet2. When the
> user
> chooses "yes" in any row in column L, the data from columns B:K in that
> same
> row should get special pasted (value only) to the first open row on
> sheet2.
> It doesn't work - the range gets copied and nothing gets special pasted.
>
> Here's my code:
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> Application.EnableEvents = False
> On Error GoTo Whoops
>
> If Target.Column = 12 Then 'column L Half Credit
> If Target.Row > 5 Then
> Dim rw As Integer
> rw = Target.Row
> Dim halfRange As String
> halfRange = "B" & rw & ":K" & rw
> If Target.Value = "yes" Then
> Range(halfRange).Select 'this grabs the half credit
> policy
> Selection.Copy
> Sheet2.Range("B3:B8000").Find(What:="",
> After:=Range("B3:B8000").Cells(1), LookIn:=xlFormulas, LookAt _
> :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
> False).Select
> Selection.PasteSpecial Paste:=xlPasteValues, _
> Operation:=xlNone, skipblanks:=False, Transpose:=False
> Application.CutCopyMode = False 'Clears clipboard.
> End If
> End If
> End If
>
>
> Whoops:
> Application.EnableEvents = True
>
> End Sub
>
> Thanks for any direction.


 
Reply With Quote
 
JSnow
Guest
Posts: n/a
 
      6th Mar 2009
Per, thank you! That was genius!

"Per Jessen" wrote:

> Hi
>
> You miss the sheet reference in the paste special statement.
>
> Here's how I would do it:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim TargetRow As Long
> Dim halfRange As String
> Dim CopyToRow As Long
>
> Application.EnableEvents = False
> 'On Error GoTo Whoops
>
> If Target.Column = 12 Then 'column L Half Credit
> If Target.Row > 5 Then
> TargetRow = Target.Row
> halfRange = "B" & TargetRow & ":K" & TargetRow
> If Target.Value = "yes" Then ' Case sensitive
> If Sheet2.Range("B3") = "" Then
> CopyToRow = 3
> Else
> CopyToRow = Sheet2.Range("B2").End(xlDown).Row + 1 'Assume
> headings in B2
> End If
> Range(halfRange).Copy
> Sheet2.Range("B" & CopyToRow).PasteSpecial Paste:=xlPasteValues,
> _
> Operation:=xlNone, skipblanks:=False, Transpose:=False
> Application.CutCopyMode = False 'Clears clipboard.
> End If
> End If
> End If
> 'Whoops:
> Application.EnableEvents = True
> End Sub
>
> Regards,
> Per
>
> "JSnow" <(E-Mail Removed)> skrev i meddelelsen
> news:6562600F-1AA6-40FA-AFCC-(E-Mail Removed)...
> > I'm trying to copy/special paste a range of information to the first
> > available row on another sheet called 'Half Payout' or sheet2. When the
> > user
> > chooses "yes" in any row in column L, the data from columns B:K in that
> > same
> > row should get special pasted (value only) to the first open row on
> > sheet2.
> > It doesn't work - the range gets copied and nothing gets special pasted.
> >
> > Here's my code:
> > Private Sub Worksheet_Change(ByVal Target As Range)
> >
> > Application.EnableEvents = False
> > On Error GoTo Whoops
> >
> > If Target.Column = 12 Then 'column L Half Credit
> > If Target.Row > 5 Then
> > Dim rw As Integer
> > rw = Target.Row
> > Dim halfRange As String
> > halfRange = "B" & rw & ":K" & rw
> > If Target.Value = "yes" Then
> > Range(halfRange).Select 'this grabs the half credit
> > policy
> > Selection.Copy
> > Sheet2.Range("B3:B8000").Find(What:="",
> > After:=Range("B3:B8000").Cells(1), LookIn:=xlFormulas, LookAt _
> > :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
> > False).Select
> > Selection.PasteSpecial Paste:=xlPasteValues, _
> > Operation:=xlNone, skipblanks:=False, Transpose:=False
> > Application.CutCopyMode = False 'Clears clipboard.
> > End If
> > End If
> > End If
> >
> >
> > Whoops:
> > Application.EnableEvents = True
> >
> > End Sub
> >
> > Thanks for any direction.

>
>

 
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
Open WB, copy each sh. & paste into other WB, regardless of tab na Driftwood Microsoft Excel Misc 0 29th Jan 2010 02:06 PM
Outlook 2003 Copy & Paste Strangeness - Destination Must be Open Prior to Copy antony01@theUpwards.net Microsoft Outlook 0 14th Mar 2007 05:34 AM
Outlook 2003 Copy & Paste Strangeness - Destination Must be Open Prior to Copy antony01@theUpwards.net Microsoft Outlook Discussion 0 14th Mar 2007 05:23 AM
open copy paste =?Utf-8?B?QW9uZ2h1cw==?= Microsoft Excel Programming 3 12th Aug 2005 05:00 PM
open, copy, and paste jacksonz Microsoft Excel Programming 1 21st Jul 2005 03:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:38 AM.