#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Code error!

Hi All,

I have the following code for a button to add a new row below the last line
of information entered. However, the new line that is ceated copies the data
from the line it is copying. i want to copy the formatting but not the actual
information, i would like the new row to be blank. how would i do this?

Private Sub CommandButton1_Click()
'Insert Entire Row
With Sheet1
..Unprotect
With .Range("code")
.End(xlDown).Offset(1, 0).EntireRow.Insert
.Offset(1, 0).Resize(1, 20).Copy
Destination:=.End(xlDown).Offset(1, 0)
Application.CutCopyMode = False
.End(xlDown).Offset(1, 0).Select
End With
..Protect
End With
End Sub

Thanks in advance!

: )
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Code error!

Hi RemySS,
Try this

Private Sub CommandButton1_Click()
'Insert Entire Row
With Sheet1
..Unprotect
With .Range("code")
.End(xlDown).Offset(1, 0).EntireRow.Insert

With .Offset(1, 0)
.Resize(1, 20).Copy
.PasteSpecial Paste:=xlPasteFormats
End With
Application.CutCopyMode = False
.End(xlDown).Offset(1, 0).Select
End With
..Protect
End With
End Sub

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Code error!

Hi Ken,

this worked, but also deleted the formatting from the row it copied. the
second column is 5 merged cells - they went to unmerged in both the top row
and the inserted new row. How can i keep that the same?

Thanks!

"Ken Johnson" wrote:

Hi RemySS,
Try this

Private Sub CommandButton1_Click()
'Insert Entire Row
With Sheet1
..Unprotect
With .Range("code")
.End(xlDown).Offset(1, 0).EntireRow.Insert

With .Offset(1, 0)
.Resize(1, 20).Copy
.PasteSpecial Paste:=xlPasteFormats
End With
Application.CutCopyMode = False
.End(xlDown).Offset(1, 0).Select
End With
..Protect
End With
End Sub

Ken Johnson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Code error!

Hi Remy,
I see that any merged cells become unmerged, and the same happens with
Center Across Selection. Its nearly 3:00 am here and I must get some
sleep. Maybe you could start a new topic about loss of cell merging and
hopefully one of the MVPs can sort it out. Cell merging is the bane of
every Excel user's existance and the MVPs usually poo poo its use, but
here is a case of Center Across Selection formatting also being lost so
you need an MVP to sort it out. I thought all I did was change it from
copy/paste to copy then paste special/ paste formats. The With/End
Withs are a bit convoluted, so I may have overlooked something because
of that.
Sorry I can't help anymore, must get to bed zzzzzzzz

Ken Johnson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Code error!

Ken,

Ok, thanks for the first bit of code!



"Ken Johnson" wrote:

Hi Remy,
I see that any merged cells become unmerged, and the same happens with
Center Across Selection. Its nearly 3:00 am here and I must get some
sleep. Maybe you could start a new topic about loss of cell merging and
hopefully one of the MVPs can sort it out. Cell merging is the bane of
every Excel user's existance and the MVPs usually poo poo its use, but
here is a case of Center Across Selection formatting also being lost so
you need an MVP to sort it out. I thought all I did was change it from
copy/paste to copy then paste special/ paste formats. The With/End
Withs are a bit convoluted, so I may have overlooked something because
of that.
Sorry I can't help anymore, must get to bed zzzzzzzz

Ken Johnson


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
error in code des-sa[_2_] Excel Discussion (Misc queries) 5 July 3rd 08 08:09 AM
Error in Code N.F[_2_] Excel Discussion (Misc queries) 9 June 27th 07 06:48 PM
Error Code 6 Dave Excel Programming 5 September 7th 05 07:12 PM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


All times are GMT +1. The time now is 02:36 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"