Results 1 to 5 of 5

Thread: [Resolved] Deleting Rows in Excel via Access

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    66

    Resolved [Resolved] Deleting Rows in Excel via Access

    In my code, I am trying to delete a selected set of rows using:

    VB Code:
    1. 'delete rows
    2.         If count > 0 Then
    3.             Rows("1:12").Select
    4.             Selection.Delete Shift:=xlUp
    5.         End If

    When ran, it carries out the deletion. However when I close excel/quit the application, an excel instance still remains - until I stop the process.

    From reading past posts, this is symtom of incorrect code that works (?)...causing an excel instance to hang. The soluiton is to pin-point the code that is causing this. In my case Rows("1:12").Select is the problem.

    Is there another way to delete rows in excel?

    Last edited by whiteWay; Jul 16th, 2005 at 11:47 AM.

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

    Re: Deleting Rows in Excel via Access

    You need to post the code you wrote to create the Excel application instance and open the workbook, etc. I see your using
    the default objects "Rows" and the "Selection" object. Where are your variable objects that fully qualify them? That is the problem and
    you may also not be quiting the app using your Excel application onject.
    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
    Lively Member
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    66

    Re: Deleting Rows in Excel via Access

    When referencing Excel objects from Access, use the parent object to get methods/properties. When cutting and pasting from an excel macro, excel omits the parent object (in this case the application object and current sheet)

    VB Code:
    1. Dim xlApp As Excel.Application, sheet As Excel.Worksheet
    2.  
    3.         With xlApp
    4.  
    5.         Set sheet = .ActiveWorkbook.Sheets("Header")
    6.  
    7.         'delete rows
    8.         If count > 0 Then
    9.             sheet.Rows("1:12").Select
    10.             .Selection.Delete Shift:=xlUp
    11.         End If
    12.  
    13.         end With

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    66

    Re: Deleting Rows in Excel via Access

    Sorry, we posted at the same time.

    I finally figured it out myself, and you were right as well. Thanks.

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

    Re: [Resolved] Deleting Rows in Excel via Access

    's on solving it.

    Its not a waste because some member may do a search or read this thread and it will help them, etc.
    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