#1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Macro Paste

Writing a macro and trying to copy several cells from sheet 1 and then
paste into sheet 2 while not pasting over existing data. Is there a
way to auto select the next blank cell in the column in sheet 2 and
paste. Say if A1 is not blank, then auto select A2 instead and so on.

I'm using sheet 1 as the data entry sheet and then sheet 2 to collect
the data for creating charts, etc. Don't want to paste over existing
data.

Tom

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Macro Paste

Tom

Sub findbottom()
Dim rng1 As Range
Set rng1 = Selection
rng1.Copy Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0)

Application.CutCopyMode = False
End Sub


Gord Dibben MS Excel MVP

On 27 Jan 2007 16:35:41 -0800, "Tom" wrote:

Writing a macro and trying to copy several cells from sheet 1 and then
paste into sheet 2 while not pasting over existing data. Is there a
way to auto select the next blank cell in the column in sheet 2 and
paste. Say if A1 is not blank, then auto select A2 instead and so on.

I'm using sheet 1 as the data entry sheet and then sheet 2 to collect
the data for creating charts, etc. Don't want to paste over existing
data.

Tom


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Macro Paste

Range("A" & Rows.Count).End(xlUp).Offset(1,0).Select
then do the paste.

there are two times this will not work properly:
#1 - the column is empty, it will paste at A2 instead of A1
#2 - the column is full and there's no room to paste at all.
#3 - you're so close to the end of the sheet that the paste fails because
there are too many rows to be pasted.

To cover #1 and #2:
On Error Resume Next
Range("A" & Rows.Count).End(xlUp).Offset(1,0).Select
If Err<0 Or Not(IsEmpty(ActiveCell)) Then
Err.Clear
On Error Goto 0
MsgBox "No Room to Paste"
Exit Sub
End If
On Error Goto 0
'continue with paste operation

P.S. for Excel 2007, use Rows.CountLarge instead of Rows.Count

"Tom" wrote:

Writing a macro and trying to copy several cells from sheet 1 and then
paste into sheet 2 while not pasting over existing data. Is there a
way to auto select the next blank cell in the column in sheet 2 and
paste. Say if A1 is not blank, then auto select A2 instead and so on.

I'm using sheet 1 as the data entry sheet and then sheet 2 to collect
the data for creating charts, etc. Don't want to paste over existing
data.

Tom


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Macro Paste

Also, see Chip Pearson's response to this question which is pretty much the
same one you've just asked:
http://www.microsoft.com/office/comm...9-59691916f5c3

"Tom" wrote:

Writing a macro and trying to copy several cells from sheet 1 and then
paste into sheet 2 while not pasting over existing data. Is there a
way to auto select the next blank cell in the column in sheet 2 and
paste. Say if A1 is not blank, then auto select A2 instead and so on.

I'm using sheet 1 as the data entry sheet and then sheet 2 to collect
the data for creating charts, etc. Don't want to paste over existing
data.

Tom


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro Paste

If it is possible that the cell in the first Column a of the selection is empty then look here
http://www.rondebruin.nl/copy1.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Gord Dibben" <gorddibbATshawDOTca wrote in message ...
Tom

Sub findbottom()
Dim rng1 As Range
Set rng1 = Selection
rng1.Copy Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0)

Application.CutCopyMode = False
End Sub


Gord Dibben MS Excel MVP

On 27 Jan 2007 16:35:41 -0800, "Tom" wrote:

Writing a macro and trying to copy several cells from sheet 1 and then
paste into sheet 2 while not pasting over existing data. Is there a
way to auto select the next blank cell in the column in sheet 2 and
paste. Say if A1 is not blank, then auto select A2 instead and so on.

I'm using sheet 1 as the data entry sheet and then sheet 2 to collect
the data for creating charts, etc. Don't want to paste over existing
data.

Tom




  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Macro Paste

Below is what I tried to run but I get a compile error: Sub or
Function not defined at line 6 Lr =

Sub copy_1_Values_PasteSpecial()
Dim sourceRange As Range
Dim destrange As Range
Dim Lr As Long
Application.ScreenUpdating = False
Lr = LastRow(Sheets("Log")) + 1
Set sourceRange = Sheets("Temp").Range("C7:W12")
Set destrange = Sheets("Log").Range("C" & Lr)
sourceRange.Copy
destrange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

On Jan 27, 8:15 pm, JLatham <HelpFrom @ Jlathamsite.com.(removethis)
wrote:
Also, see Chip Pearson's response to this question which is pretty much the
same one you've just asked:http://www.microsoft.com/office/comm....mspx?dg=micro...



"Tom" wrote:
Writing a macro and trying to copy several cells from sheet 1 and then
paste into sheet 2 while not pasting over existing data. Is there a
way to auto select the next blank cell in the column in sheet 2 and
paste. Say if A1 is not blank, then auto select A2 instead and so on.


I'm using sheet 1 as the data entry sheet and then sheet 2 to collect
the data for creating charts, etc. Don't want to paste over existing
data.


Tom- Hide quoted text -- Show quoted text -


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro Paste

that is because your code is looking for a separate function named lastrow.
If you don't supply one, then you can just use

Sub copy_1_Values_PasteSpecial()
Dim sourceRange As Range
Dim destrange As Range
Dim Lr As Long
Application.ScreenUpdating = False
Lr = Sheets("Log").Cells(rows.count,"C").End(xlup).row + 1
Set sourceRange = Sheets("Temp").Range("C7:W12")
Set destrange = Sheets("Log").Range("C" & Lr)
sourceRange.Copy
destrange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

--
Regards,
Tom Ogilvy


"Tom" wrote in message
oups.com...
Below is what I tried to run but I get a compile error: Sub or
Function not defined at line 6 Lr =

Sub copy_1_Values_PasteSpecial()
Dim sourceRange As Range
Dim destrange As Range
Dim Lr As Long
Application.ScreenUpdating = False
Lr = LastRow(Sheets("Log")) + 1
Set sourceRange = Sheets("Temp").Range("C7:W12")
Set destrange = Sheets("Log").Range("C" & Lr)
sourceRange.Copy
destrange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

On Jan 27, 8:15 pm, JLatham <HelpFrom @ Jlathamsite.com.(removethis)
wrote:
Also, see Chip Pearson's response to this question which is pretty much
the
same one you've just
asked:http://www.microsoft.com/office/comm....mspx?dg=micro...



"Tom" wrote:
Writing a macro and trying to copy several cells from sheet 1 and then
paste into sheet 2 while not pasting over existing data. Is there a
way to auto select the next blank cell in the column in sheet 2 and
paste. Say if A1 is not blank, then auto select A2 instead and so on.


I'm using sheet 1 as the data entry sheet and then sheet 2 to collect
the data for creating charts, etc. Don't want to paste over existing
data.


Tom- Hide quoted text -- Show quoted text -




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
copy multiple worksheets of a workbook, and paste onto a Word document ( either create new doc file or paste onto an existing file.) I need this done by VBA, Excel Macro Steven Excel Programming 1 October 17th 05 08:56 AM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM
Cut and Paste using Macro gives paste special method error Lourens Pentz Excel Programming 3 November 21st 04 10:42 PM
Macro to Paste to specific line, and continue to Paste each time on next row not over tomkarakowski[_2_] Excel Programming 1 May 28th 04 06:50 PM
Macro to Copy/Paste then Paste to Next Line tomkarakowski Excel Programming 1 May 28th 04 01:19 AM


All times are GMT +1. The time now is 10:30 AM.

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

About Us

"It's about Microsoft Excel"