Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 1
Default cannot insert row in vba

I have a macro that works fine in excel 2007 but not 2010. It crashes when I try to insert a row, and then if I try to insert it myself, i get the error message: "Cannot shift object off sheet."

here is the code:

Sub Synthese2(an1, an2, an5, LMainWB, LNewWB)
Dim Row, Row1, Row2, n, Col As Integer
Dim LNewWB2 As String

Call Module1.Copiervalue("Feuil1", "NomSc", "Exec Summary", "NomS")
Call Module1.Copiervalue("Feuil1", "_Sc2", "Exec Summary", "Scoller2")
Call Module1.Copiervalue("Feuil1", "_Sc3", "Exec Summary", "Scoller3")
Call Module1.Copiervalue("Feuil1", "_Sc4", "Exec Summary", "Scoller4")
Call Module1.Copiervalue("Feuil1", "_Sc5", "Exec Summary", "Scoller5")
Sheets("Exec Summary").Select
Application.Goto Reference:="A.Exercice"
ActiveCell.FormulaR1C1 = an1
If an5 < CStr(0) Then
n = an1 - an2 - 1
Application.Goto Reference:="_Ref1"
Row1 = Application.ActiveCell.Row
Range("A" & CStr(Row1 + 1) & ":C" & CStr(Row1 + 3)).Select
Selection.Cut
Workbooks.Add
ActiveSheet.Paste
ActiveWindow.Close SaveChanges:=False
Range("A" & CStr(Row1 + 1) & ":C" & CStr(Row1 + 3)).Select
Selection.Delete Shift:=xlUp
Windows(LNewWB).Activate
Sheets("Exec Summary").Select
Application.Goto Reference:="_Ref2"
Rown = Application.ActiveCell.Row
Sheets("Exec Summary").Range("A" & CStr(Rown - an5) & ":C" & CStr(Rown - 1)).Select
Selection.Copy
Windows(LMainWB).Activate
Sheets("Exec Summary").Select
Application.Goto Reference:="Ref"
Row = Application.ActiveCell.Row
Selection.Insert Shift:=xlDown // this is where the macro crashes
Windows(LNewWB).Activate
Sheets("Exec Summary").Select
Sheets("Exec Summary").Range("A" & CStr(Rown - an5) & ":A" & CStr(Rown - 1)).Select
Selection.Copy
Windows(LMainWB).Activate
Sheets("Exec Summary").Select
Sheets("Exec Summary").Range("A" & CStr(Row)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
For i = 0 To an5
Sheets("Exec Summary").Rows(CStr(Row1 + 1 + i) & ":" & CStr(Row1 + 1 + i)).RowHeight = 350
Next i
Application.Goto Reference:="_Ref2"
Selection.Rows.AutoFit
If n 0 Then
For i = 1 To n
Call Synthese.Cut
Next i
End If
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default cannot insert row in vba

You have shapes or comments that won't fit in the visible cells area,
which your action will force them to shift 'off' the sheet. This
suggests you have deleted cols/rows outside your used range and so the
objects have no where to shift to.

--
Garry

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


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
Insert new Worksheet with name, and insert the sheet into itsalphabetical / numerical location S Davis Excel Programming 0 May 12th 08 07:13 PM
insert row / insert column command buttons fairgreen Excel Worksheet Functions 1 October 29th 07 02:41 PM
How can I insert a date with an icon (calendar) insert Alfredo Mederico[_2_] Excel Discussion (Misc queries) 4 September 21st 07 01:20 AM
Macro to insert copy and insert formulas only to next blank row bob Excel Programming 0 June 30th 06 12:02 PM
Insert cell/format/text/fontsize and auto insert into header? Unfurltheflag Excel Programming 2 November 3rd 04 05:39 PM


All times are GMT +1. The time now is 09:45 AM.

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

About Us

"It's about Microsoft Excel"