Computing.Net > Forums > Office Software > Excel: Remove data to another sheet

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel: Remove data to another sheet

Reply to Message Icon

Name: Alex2002
Date: April 23, 2008 at 10:10:39 Pacific
OS: Vista Ultimate
CPU/Ram: 4200/2GB
Comment:

Got a bit of an Excel query that I am struggling with.

Say you have two worksheets - Data1 and Data2.

Both sheets will have identical columns and column headings. But Data1 will be the main sheet where all the data is inputted to, save for one column.

When this column does get data entered into it, I want the spreadsheet to move that said row to Data2, also meaning that it is deleted from Data1. Then, the next time this action occurs, I will obviously need it to move the data to the next row down on Data2.

I've been fiddling with a few Macro examples I've found but no luck. Is there a simple way to do this?

Any help would be GREATLY appreciated

Cheers



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: April 24, 2008 at 11:12:59 Pacific
Reply:

Assuming you want to move the row immediately after the data is entered, use a sheet-level Change macro with the data entry Column as the target.

When a change is made to the target column, cut/paste the target row to the other sheet.

Use this to keep track of how many rows there are in your destination sheet:

LastRow = Sheets("Data2").Range("A" & Rows.Count).End(xlUp).Row


0

Response Number 2
Name: Alex2002
Date: April 26, 2008 at 04:36:10 Pacific
Reply:

Thanks for the advice.

I'm still looking into this and still having problems. I did find this example online:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 6 And Target.Cells.Count = 1 Then
If Target.Value <> "" Then
Target.EntireRow.Cut
Sheets("Sheet2").Activate
ActiveSheet.Range("A1").Select
ActiveSheet.Range("A1").End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
Sheets("Sheet1").Activate
Target.EntireRow.Delete
End If
End If
End Sub

....But I just get this error when testing it:

http://i72.photobucket.com/albums/i...

I have no idea why it's refusing to work!


0

Response Number 3
Name: DerbyDad03
Date: April 26, 2008 at 14:21:34 Pacific
Reply:

What did you try as far as troubleshooting the code to see why it was giving you the error?

If you clicked Debug in the error window it would have highlighted:

ActiveSheet.Range("A1").End(xlDown).Offset(1, 0).Select

Excel is finicky about .End(xlDown) in an empty column or a column with data in just Row 1. In those cases it goes all the way down to the very last cell in the column. Therefore when you try to Select the next cell down with .Offset(1,0) it crashes.

Put some data in A2 and the code will sort of work, but not really.

When I tried it (after putting something in A2 so it didn't error) it did indeed cut the data from Sheet1 and put it in Sheet2, but it deleted the wrong row in Sheet1. When the code pasted the data into Sheet2, it reset the Target address to the destination address in Sheet2 and then deleted the corresponding row in Sheet1.

In addition, rarely do you need to Activate a sheet or Select a cell to perform an operation on it. It's much more efficient if you let VBA do it's work in the background.

Here's the code I would use:


Private Sub Worksheet_Change(ByVal Target As Range)
'Determine if the Target is in
'Column 6 and contains data
If Target.Column = 6 And Target.Cells.Count = 1 Then
If Target.Value <> "" Then
'Store Target Address
MyAddress = Target.Address
'Find Next Empty Cell In Sheet2 Column A
NextRow = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row + 1
'Cut and Paste Target Row to Sheet2
Target.EntireRow.Cut Destination:=Sheets(2).Range("A" & NextRow)
'Delete Target Row in Sheet1
Range(MyAddress).EntireRow.Delete
End If
End If
End Sub



0

Response Number 4
Name: Alex2002
Date: May 3, 2008 at 04:49:01 Pacific
Reply:

Thank you SO much, you are a legend. Very very helpful

Cheers


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Excel: Remove data to another sheet

get data from another sheet www.computing.net/answers/office/get-data-from-another-sheet/5429.html

excel extracting data www.computing.net/answers/office/excel-extracting-data/4977.html

Save cell contents to another cell auto www.computing.net/answers/office/save-cell-contents-to-another-cell-auto/9708.html