Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 21
Smile VBA - Insert row, copy contents of original row except for contents of column A

Hi. I am using the code below to insert a row by double-clicking a cell. The code then copies formulas (and apparently dates) from the original row to the new row. Is there any way for me to adjust this code so the cell in column A is blank after the insert? If so, I need it to work like this for all 30+ pages of the workbook. Here's the code I have in ThisWorkbook:

Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
  'David McRitchie,  2007-09-07    insrtrow.htm on double-click
  '-- will copy more often than  Extend Formulas and Format (tools option)
  Cancel = True
  Target.EntireRow.Copy
  Cells(Target.Row + 1, 1).EntireRow.Insert
  Cells(Target.Row + 1, 1).EntireRow.Select
  ActiveSheet.Paste
  Application.CutCopyMode = False
  On Error Resume Next
  '-- customize range for what cells constants can be removed --
  Intersect(Selection, Range("b:IV")).SpecialCells(xlConstants).ClearContents
  On Error GoTo 0
End Sub

Thanks!
  #2   Report Post  
Junior Member
 
Posts: 21
Default

This has been resolved. Here's the new code:

Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    With Target
        .Offset(1).EntireRow.Insert
        .EntireRow.Copy .Offset(1).EntireRow(1)
        With .Offset(1).EntireRow
            .Cells(1).ClearContents
            On Error Resume Next
            .SpecialCells(2).ClearContents
            On Error GoTo 0
        End With
    End With
End Sub
Thanks!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default VBA - Insert row, copy contents of original row except for contents of column A

Not sure what the other code in your sample does, but this does what
you asked for on any sheet you double-click on...

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal
Target As Range, Cancel As Boolean)
Cancel = True
With Target
.EntireRow.Copy: Cells(.Row, 1).Offset(1).Insert Shift:=xlDown
End With
With Cells(Target.Row, 1).Offset(1): .Select: .ClearContents: End
With
End Sub

Note that you will now have to just start typing to enter EditMode in
cells, OR use the F2 keyboard shortcut.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default VBA - Insert row, copy contents of original row except forcontents of column A

On Feb 20, 5:19*pm, Royzer wrote:
Hi. I am using the code below to insert a row by double-clicking a cell.
The code then copies formulas (and apparently dates) from the original
row to the new row. Is there any way for me to adjust this code so the
cell in column A is blank after the insert? If so, I need it to work
like this for all 30+ pages of the workbook. Here's the code I have in
ThisWorkbook:

Code:
--------------------

* Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
* 'David McRitchie, *2007-09-07 * *insrtrow.htm on double-click
* '-- will copy more often than *Extend Formulas and Format (tools option)
* Cancel = True
* Target.EntireRow.Copy
* Cells(Target.Row + 1, 1).EntireRow.Insert
* Cells(Target.Row + 1, 1).EntireRow.Select
* ActiveSheet.Paste
* Application.CutCopyMode = False
* On Error Resume Next
* '-- customize range for what cells constants can be removed --
* Intersect(Selection, Range("b:IV")).SpecialCells(xlConstants).ClearCont ents
* On Error GoTo 0
* End Sub

--------------------

Thanks!

--
Royzer

I think thisis what you want.

Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, Cancel As Boolean)
'SAS Copies targetrow and clears columns b
Application.ScreenUpdating = False
With Target
Rows(.Row + 1).Insert
Rows(.Row).Copy .Offset(1)
Cells(.Row + 1, 2).Resize(, 255).ClearContents
.Offset(1, 1).Select
End With
Application.ScreenUpdating = True
End Sub
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default VBA - Insert row, copy contents of original row except forcontents of column A

On Feb 21, 7:28*am, Don Guillett wrote:
On Feb 20, 5:19*pm, Royzer wrote:







Hi. I am using the code below to insert a row by double-clicking a cell..
The code then copies formulas (and apparently dates) from the original
row to the new row. Is there any way for me to adjust this code so the
cell in column A is blank after the insert? If so, I need it to work
like this for all 30+ pages of the workbook. Here's the code I have in
ThisWorkbook:


Code:
--------------------


* Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
* 'David McRitchie, *2007-09-07 * *insrtrow.htm on double-click
* '-- will copy more often than *Extend Formulas and Format (tools option)
* Cancel = True
* Target.EntireRow.Copy
* Cells(Target.Row + 1, 1).EntireRow.Insert
* Cells(Target.Row + 1, 1).EntireRow.Select
* ActiveSheet.Paste
* Application.CutCopyMode = False
* On Error Resume Next
* '-- customize range for what cells constants can be removed --
* Intersect(Selection, Range("b:IV")).SpecialCells(xlConstants).ClearCont ents
* On Error GoTo 0
* End Sub


--------------------


Thanks!


--
Royzer


I think thisis what you want.

Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, Cancel As Boolean)
'SAS Copies targetrow and clears columns b
Application.ScreenUpdating = False
With Target
Rows(.Row + 1).Insert
Rows(.Row).Copy .Offset(1)
Cells(.Row + 1, 2).Resize(, 255).ClearContents
*.Offset(1, 1).Select
End With
Application.ScreenUpdating = True
End Sub


Should have been this in the ThisWorkbook module
restricted to a double click ONLY in column A

Private Sub Workbook_SheetBeforeDoubleClick _
(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)

If Target.Column < 1 Then Exit Sub
Application.ScreenUpdating = False
With Target
Rows(.Row + 1).Insert
Rows(.Row).Copy .Offset(1)
Cells(.Row + 1, 2).Resize(, 255).ClearContents
..Offset(1, 1).Select
End With
Application.ScreenUpdating = True
End Sub
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
How can I sort contents of one column based on the contents ofanother column? [email protected] Excel Programming 1 February 9th 08 12:29 PM
Excel Macro to Insert the contents of one column to other Dhawal Excel Discussion (Misc queries) 5 October 5th 06 01:22 PM
Copy row contents based on contents naterator Excel Programming 1 June 3rd 06 06:11 PM
Insert contents of various cells in a column into one cell? TextCells Excel Discussion (Misc queries) 1 April 2nd 06 10:41 PM
Find a value, then insert a row below that row and copy the contents to the new row stelllar Excel Programming 4 February 15th 05 12:29 PM


All times are GMT +1. The time now is 04:11 PM.

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"