Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 54
Default copy paste to first first open row

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.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default copy paste to first first open row

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" skrev i meddelelsen
...
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.


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 54
Default copy paste to first first open row

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" skrev i meddelelsen
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't Copy and Paste or Paste Special between Excel Workbooks wllee Excel Discussion (Misc queries) 5 April 29th 23 03:43 AM
Copy, paste without file name referenced after paste AusTexRich Excel Discussion (Misc queries) 6 September 23rd 08 02:57 AM
Macro to open workbook and copy and paste values in to orig workbo Dena X Excel Worksheet Functions 1 December 15th 05 11:13 PM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM
I cannot paste from one workbook to another. Copy works, paste do. JimmyMc Excel Discussion (Misc queries) 1 June 10th 05 03:54 PM


All times are GMT +1. The time now is 03:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"