Results 1 to 4 of 4

Thread: [RESOLVED] How to Insert a row in Excel ?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Resolved [RESOLVED] How to Insert a row in Excel ?

    I have an excel file with data from A1 to A10, how would I insert a row before lets say, Row 5 ?

    I have this code:
    VB Code:
    1. Dim xlApp As Excel.Application
    2.     Dim wkbTemplateBook As Excel.Workbook
    3.     Dim wksTemplateSheet As Excel.Worksheet
    4.    
    5.     Set xlApp = New Excel.Application
    6.     Set wkbTemplateBook = xlApp.Workbooks.Open(Me.txtTemplate.Text)
    7.     Set wksTemplateSheet = wkbTemplateBook.Worksheets(1)
    8.    
    9.     With wksTemplateSheet
    10.         ' how to insert a row ?
    11.     End With

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to Insert a row in Excel ?

    VB Code:
    1. wksTemplateSheet .Rows("4:4").Select
    2. Selection.Insert Shift:=xlDown
    Last edited by RobDog888; Jul 14th, 2005 at 05:09 PM. Reason: fix tags
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How to Insert a row in Excel ?

    Thanks RobDog888...

    A not so important question: Is there a way to insert lets say 50 rows in one call ? or do I have to call the Insert 50 times in a loop ?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to Insert a row in Excel ?

    What ever number of rows you select, that amount will be inserted.
    VB Code:
    1. wksTemplateSheet.Rows("1:10").Select
    2. Selection.Insert Shift:=xlDown
    10 rows inserted.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width