PC Review


Reply
Thread Tools Rate Thread

Cut and Paste

 
 
Chip Dukes
Guest
Posts: n/a
 
      18th Apr 2010
I'm trying to write a simple cut and paste routine that triggers when
information is changed in a certain column ... the current row is supposed to
be cut then pasted into a seperate sheet in the same workbook ... see code
below (comments explain)

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 3 Then

'Select the current Row and Cut it
Rows(ActiveCell.Row).Cut

'Move to the catch sheet
Sheets("Catch Sheet").Select

'Find the first empty row
Range("A1").Select
Do Until Selection.Value = ""
Selection.Offset(1, 0).Select
Loop

'Select the row just found
Rows(ActiveCell.Row).Select

'Paste into the selected row
ActiveSheet.Paste

'Go back to the master sheet and clean up
Sheets("Test Sheet").Select
Selection.Delete Shift:=xlUp

Else
Exit Sub
End If

End Sub


The problem seems to be with line 12

Range("A1").Select

I am getting an error ... "select method of Range class failed" ...

Any suggestions.

Chip Dukes
(new to excel programming)
 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      18th Apr 2010
hi
when using sheet code, you cannot select a range on another sheet.
in a way, sheet code restrick you to the sheet that owns the code.
but you can manipulate other sheets.
try this.........
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 3 Then
Target.EntireRow.Copy Destination:= _
Sheets("Catch Sheet").Range("A65000").End(xlUp).Offset(1, 0)
Target.EntireRow.Delete shift:=xlUp
Else
Exit Sub
End If
End Sub

Regards
FSt1

"Chip Dukes" wrote:

> I'm trying to write a simple cut and paste routine that triggers when
> information is changed in a certain column ... the current row is supposed to
> be cut then pasted into a seperate sheet in the same workbook ... see code
> below (comments explain)
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> If Target.Column = 3 Then
>
> 'Select the current Row and Cut it
> Rows(ActiveCell.Row).Cut
>
> 'Move to the catch sheet
> Sheets("Catch Sheet").Select
>
> 'Find the first empty row
> Range("A1").Select
> Do Until Selection.Value = ""
> Selection.Offset(1, 0).Select
> Loop
>
> 'Select the row just found
> Rows(ActiveCell.Row).Select
>
> 'Paste into the selected row
> ActiveSheet.Paste
>
> 'Go back to the master sheet and clean up
> Sheets("Test Sheet").Select
> Selection.Delete Shift:=xlUp
>
> Else
> Exit Sub
> End If
>
> End Sub
>
>
> The problem seems to be with line 12
>
> Range("A1").Select
>
> I am getting an error ... "select method of Range class failed" ...
>
> Any suggestions.
>
> Chip Dukes
> (new to excel programming)

 
Reply With Quote
 
Chip Dukes
Guest
Posts: n/a
 
      18th Apr 2010
Nice ... very, very nice

Thank you

Chip

"FSt1" wrote:

> hi
> when using sheet code, you cannot select a range on another sheet.
> in a way, sheet code restrick you to the sheet that owns the code.
> but you can manipulate other sheets.
> try this.........
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> If Target.Column = 3 Then
> Target.EntireRow.Copy Destination:= _
> Sheets("Catch Sheet").Range("A65000").End(xlUp).Offset(1, 0)
> Target.EntireRow.Delete shift:=xlUp
> Else
> Exit Sub
> End If
> End Sub
>
> Regards
> FSt1
>
> "Chip Dukes" wrote:
>
> > I'm trying to write a simple cut and paste routine that triggers when
> > information is changed in a certain column ... the current row is supposed to
> > be cut then pasted into a seperate sheet in the same workbook ... see code
> > below (comments explain)
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> >
> > If Target.Column = 3 Then
> >
> > 'Select the current Row and Cut it
> > Rows(ActiveCell.Row).Cut
> >
> > 'Move to the catch sheet
> > Sheets("Catch Sheet").Select
> >
> > 'Find the first empty row
> > Range("A1").Select
> > Do Until Selection.Value = ""
> > Selection.Offset(1, 0).Select
> > Loop
> >
> > 'Select the row just found
> > Rows(ActiveCell.Row).Select
> >
> > 'Paste into the selected row
> > ActiveSheet.Paste
> >
> > 'Go back to the master sheet and clean up
> > Sheets("Test Sheet").Select
> > Selection.Delete Shift:=xlUp
> >
> > Else
> > Exit Sub
> > End If
> >
> > End Sub
> >
> >
> > The problem seems to be with line 12
> >
> > Range("A1").Select
> >
> > I am getting an error ... "select method of Range class failed" ...
> >
> > Any suggestions.
> >
> > Chip Dukes
> > (new to excel programming)

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      18th Apr 2010
Try this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lr As Long
If Target.Column = 3 Then
lr = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Target.EntireRow.Cut Sheets("Sheet2").Range("A" & lr + 1)
Target.EntireRow.Delete
Application.CutCopyMode = False
End If
End Sub




"Chip Dukes" <(E-Mail Removed)> wrote in message
news:372EFD9C-B3F9-4688-853C-(E-Mail Removed)...
> I'm trying to write a simple cut and paste routine that triggers when
> information is changed in a certain column ... the current row is supposed
> to
> be cut then pasted into a seperate sheet in the same workbook ... see code
> below (comments explain)
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> If Target.Column = 3 Then
>
> 'Select the current Row and Cut it
> Rows(ActiveCell.Row).Cut
>
> 'Move to the catch sheet
> Sheets("Catch Sheet").Select
>
> 'Find the first empty row
> Range("A1").Select
> Do Until Selection.Value = ""
> Selection.Offset(1, 0).Select
> Loop
>
> 'Select the row just found
> Rows(ActiveCell.Row).Select
>
> 'Paste into the selected row
> ActiveSheet.Paste
>
> 'Go back to the master sheet and clean up
> Sheets("Test Sheet").Select
> Selection.Delete Shift:=xlUp
>
> Else
> Exit Sub
> End If
>
> End Sub
>
>
> The problem seems to be with line 12
>
> Range("A1").Select
>
> I am getting an error ... "select method of Range class failed" ...
>
> Any suggestions.
>
> Chip Dukes
> (new to excel programming)



 
Reply With Quote
 
FSt1
Guest
Posts: n/a
 
      18th Apr 2010
you're welcome

"Chip Dukes" wrote:

> Nice ... very, very nice
>
> Thank you
>
> Chip
>
> "FSt1" wrote:
>
> > hi
> > when using sheet code, you cannot select a range on another sheet.
> > in a way, sheet code restrick you to the sheet that owns the code.
> > but you can manipulate other sheets.
> > try this.........
> > Private Sub Worksheet_Change(ByVal Target As Range)
> >
> > If Target.Column = 3 Then
> > Target.EntireRow.Copy Destination:= _
> > Sheets("Catch Sheet").Range("A65000").End(xlUp).Offset(1, 0)
> > Target.EntireRow.Delete shift:=xlUp
> > Else
> > Exit Sub
> > End If
> > End Sub
> >
> > Regards
> > FSt1
> >
> > "Chip Dukes" wrote:
> >
> > > I'm trying to write a simple cut and paste routine that triggers when
> > > information is changed in a certain column ... the current row is supposed to
> > > be cut then pasted into a seperate sheet in the same workbook ... see code
> > > below (comments explain)
> > >
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > >
> > > If Target.Column = 3 Then
> > >
> > > 'Select the current Row and Cut it
> > > Rows(ActiveCell.Row).Cut
> > >
> > > 'Move to the catch sheet
> > > Sheets("Catch Sheet").Select
> > >
> > > 'Find the first empty row
> > > Range("A1").Select
> > > Do Until Selection.Value = ""
> > > Selection.Offset(1, 0).Select
> > > Loop
> > >
> > > 'Select the row just found
> > > Rows(ActiveCell.Row).Select
> > >
> > > 'Paste into the selected row
> > > ActiveSheet.Paste
> > >
> > > 'Go back to the master sheet and clean up
> > > Sheets("Test Sheet").Select
> > > Selection.Delete Shift:=xlUp
> > >
> > > Else
> > > Exit Sub
> > > End If
> > >
> > > End Sub
> > >
> > >
> > > The problem seems to be with line 12
> > >
> > > Range("A1").Select
> > >
> > > I am getting an error ... "select method of Range class failed" ...
> > >
> > > Any suggestions.
> > >
> > > Chip Dukes
> > > (new to excel programming)

 
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
Copy/Paste from Outlook Task to Word - Priority won't paste Victoria@dig Microsoft Outlook Discussion 2 1st Apr 2010 08:05 PM
Outlook 2007 Macro: Paste - Paste Special - Unformatted Text Gary Petersen Microsoft Outlook VBA Programming 9 28th Dec 2009 03:37 PM
Automating copy/paste/paste special when row references change Carl LaFong Microsoft Excel Programming 4 8th Oct 2007 06:10 AM
Paste action doesn't work into text fields (is trying to paste a printscreen, not what's in the clipboard) john Q Windows XP General 8 11th Jul 2006 10:31 PM
PASTE SPECIAL - Paste Values vs Paste Unicode xterri Microsoft Excel Misc 1 30th Jun 2004 01:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:12 AM.