PC Review


Reply
Thread Tools Rate Thread

Copying Data from One sheet to another

 
 
James
Guest
Posts: n/a
 
      16th Nov 2009
Hi all

I am trying to copy cells from one sheet and paste in another using the
below. The theory is that there is a new row in both sheet 1 and 2 each day
and each day I want it to find the last row in sheet 1, copy the data in
cells B-M into the last row in sheet 2, columns F-Q. However it keeps
erroring! Does anyone have any ideas what I'm doing wrong????

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
Sheets("Sheet2").Select
Cells(Rows.Count, "C").End(xlUp).Select
Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste


Thanks in advance for any help

--
James.
 
Reply With Quote
 
 
 
 
jason
Guest
Posts: n/a
 
      16th Nov 2009
On Nov 16, 12:10*pm, James <Ja...@discussions.microsoft.com> wrote:
> Hi all
>
> I am trying to copy cells from one sheet and paste in another using the
> below. The theory is that there is a new row in both sheet 1 and 2 each day
> and each day I want it to find the last row in sheet 1, copy the data in
> cells B-M into the last row in sheet 2, columns F-Q. However it keeps
> erroring! Does anyone have any ideas what I'm doing wrong????
>
> Sheets("Sheet1").Select
> Cells(Rows.Count, "A").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
> Sheets("Sheet2").Select
> Cells(Rows.Count, "C").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste
>
> Thanks in advance for any help
>
> --
> James.


excel commands are buggy when programmed. use do loops.
 
Reply With Quote
 
jason
Guest
Posts: n/a
 
      16th Nov 2009
On Nov 16, 12:10*pm, James <Ja...@discussions.microsoft.com> wrote:
> Hi all
>
> I am trying to copy cells from one sheet and paste in another using the
> below. The theory is that there is a new row in both sheet 1 and 2 each day
> and each day I want it to find the last row in sheet 1, copy the data in
> cells B-M into the last row in sheet 2, columns F-Q. However it keeps
> erroring! Does anyone have any ideas what I'm doing wrong????
>
> Sheets("Sheet1").Select
> Cells(Rows.Count, "A").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
> Sheets("Sheet2").Select
> Cells(Rows.Count, "C").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste
>
> Thanks in advance for any help
>
> --
> James.


see post in group to "excel database" question.
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      17th Nov 2009
James, I re-wrote your code to eliminate the select keyword and to use a
different syntax for the copy/paste function. This puts the target row in a
variable for the copy and then puts the next empty row in sheet2 in a
variable for the paste function. The copy to destination syntax does not
use the Paste or PasteSpecial command, Paste is implied by the syntax
structure. Put the Dim statements at the top of your macro and give it a
try.

rw = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
rw2 = Sheets("Sheet2").Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
Range("B" & rw & ":M" & rw).Copy _
Sheets("Sheet2").Range("F" & rw2)

'remainder commented out as unneeded.
'Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
'Sheets("Sheet2").Select
'Cells(Rows.Count, "C").End(xlUp).Select
'Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste





"James" <(E-Mail Removed)> wrote in message
news:741B9167-F92F-406C-97B0-(E-Mail Removed)...
> Hi all
>
> I am trying to copy cells from one sheet and paste in another using the
> below. The theory is that there is a new row in both sheet 1 and 2 each
> day
> and each day I want it to find the last row in sheet 1, copy the data in
> cells B-M into the last row in sheet 2, columns F-Q. However it keeps
> erroring! Does anyone have any ideas what I'm doing wrong????
>
> Sheets("Sheet1").Select
> Cells(Rows.Count, "A").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
> Sheets("Sheet2").Select
> Cells(Rows.Count, "C").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste
>
>
> Thanks in advance for any help
>
> --
> James.



 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      17th Nov 2009
Hi,

Try it like this

lastrow1 = Sheets("Sheet1").Cells(Cells.Rows.Count, "B").End(xlUp).Row
lastrow2 = Sheets("Sheet2").Cells(Cells.Rows.Count, "F").End(xlUp).Row + 1
Sheets("Sheet1").Range("B" & lastrow1 & ":M" & lastrow1).Copy _
Destination:=Sheets("Sheet2").Range("F" & lastrow2)

"James" wrote:

> Hi all
>
> I am trying to copy cells from one sheet and paste in another using the
> below. The theory is that there is a new row in both sheet 1 and 2 each day
> and each day I want it to find the last row in sheet 1, copy the data in
> cells B-M into the last row in sheet 2, columns F-Q. However it keeps
> erroring! Does anyone have any ideas what I'm doing wrong????
>
> Sheets("Sheet1").Select
> Cells(Rows.Count, "A").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
> Sheets("Sheet2").Select
> Cells(Rows.Count, "C").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste
>
>
> Thanks in advance for any help
>
> --
> James.

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      17th Nov 2009
Try this

Option Explicit
Sub test()
Dim myWS As Excel.Worksheet
Dim myWS1 As Excel.Worksheet
Dim lRow As Long
Dim lRow1 As Long
Dim myRange As Excel.Range

Set myWS = Sheets("Sheet1")
lRow = myWS.Cells(myWS.Rows.Count, "A").End(xlUp).Row
Set myRange = myWS.Range("B" & lRow & ":M" & lRow)

Set myWS1 = Worksheets("Sheet2")
lRow1 = myWS1.Cells(myWS1.Rows.Count, "C").End(xlUp).Row

myRange.Copy Destination:=myWS1.Range("F" & lRow1)


End Sub

--
HTH,

Barb Reinhardt



"James" wrote:

> Hi all
>
> I am trying to copy cells from one sheet and paste in another using the
> below. The theory is that there is a new row in both sheet 1 and 2 each day
> and each day I want it to find the last row in sheet 1, copy the data in
> cells B-M into the last row in sheet 2, columns F-Q. However it keeps
> erroring! Does anyone have any ideas what I'm doing wrong????
>
> Sheets("Sheet1").Select
> Cells(Rows.Count, "A").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
> Sheets("Sheet2").Select
> Cells(Rows.Count, "C").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste
>
>
> Thanks in advance for any help
>
> --
> James.

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      17th Nov 2009
Try the below

Sub Macro()
Dim lngRowSource As Long, lngRowDest As Long
lngRowSource = Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row
lngRowDest = Sheets("Sheet2").Cells(Rows.Count, "F").End(xlUp).Row

Sheets("Sheet1").Range("B" & lngRowSource).Resize(, 12).Copy _
Sheets("Sheet2").Range("F" & lngRowDest + 1).Resize(, 12)
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"James" wrote:

> Hi all
>
> I am trying to copy cells from one sheet and paste in another using the
> below. The theory is that there is a new row in both sheet 1 and 2 each day
> and each day I want it to find the last row in sheet 1, copy the data in
> cells B-M into the last row in sheet 2, columns F-Q. However it keeps
> erroring! Does anyone have any ideas what I'm doing wrong????
>
> Sheets("Sheet1").Select
> Cells(Rows.Count, "A").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("B:M")).Copy
> Sheets("Sheet2").Select
> Cells(Rows.Count, "C").End(xlUp).Select
> Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste
>
>
> Thanks in advance for any help
>
> --
> James.

 
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
Need help Taking alot data from one sheet (if not blank) and copying toa list on another sheet. Alex Zuniga Microsoft Excel Worksheet Functions 1 25th Nov 2009 11:54 PM
copying only selected data from Sheet 1 to Sheet 2 Jaf Microsoft Excel Worksheet Functions 2 1st Sep 2009 01:01 AM
Copying the repeated data of the previous sheet to the next sheet =?Utf-8?B?U2FzaWtpcmFu?= Microsoft Excel Misc 1 25th Sep 2007 03:18 PM
Copying Data from one sheet to another sheet on a specific day =?Utf-8?B?R2F2MTIz?= Microsoft Excel Worksheet Functions 0 1st May 2007 10:17 AM
2 questions, copying data from sheet to sheet and assigning macro =?Utf-8?B?Qm9yaXM=?= Microsoft Excel Worksheet Functions 0 16th Dec 2004 06:11 PM


Features
 

Advertising
 

Newsgroups
 


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