+ Reply to Thread
Results 1 to 3 of 3

VBA code remove blank rows from all tables

  1. #1
    Registered User
    Join Date
    11-16-2018
    Location
    Philadelphia, PA
    MS-Off Ver
    Office2016
    Posts
    3

    Post VBA code remove blank rows from all tables

    I currently have this code that works for one of the tables listed (Table1), but need it to work for all tables; Table1, Table2, Table3. How do I change to code so it will look at all tables:

    Function DeleteEmptyRows()
    Dim db As DAO.Database
    Set db = CurrentDb
    Dim rs As DAO.Recordset
    Set rs = db.OpenRecordset("Table1")
    Do Until rs.EOF
    For inx = 0 To rs.Fields.Count - 1
    If IsNull(rs.Fields(inx).Value) Or Len(Trim(rs.Fields(inx).Value)) = 0 Then
    Else: Exit For
    End If
    Next
    If rs.Fields.Count = inx Then
    rs.Delete
    End If
    rs.MoveNext
    Loop

    End Function

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: VBA code remove blank rows from all tables

    Normally a function only produces results, a sub routine would delete rows.

    You can edit your post and add code tags to the VBA code.
    -
    -AA Add Code Tags.png

  3. #3
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: VBA code remove blank rows from all tables

    Hi there
    I havent tested this but i believe it may offer some help.
    the loop below will iterate through all the tables in your db except the sys tables.
    If it works, you can nest the code you have above into it or alternatively, call the function, ensuring it repeats action for all tables.
    Hope it helps

    Please Login or Register  to view this content.
    Last edited by Brian Itotia; 12-14-2018 at 06:32 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 04-17-2018, 04:50 AM
  2. Help with VB code to remove measures and row labels from PowerPivot tables
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2016, 10:12 AM
  3. [SOLVED] Update VBA code - remove blank rows in newly created sheets
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2016, 03:17 PM
  4. [SOLVED] Update existing VBA code - Remove blank rows
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-10-2016, 10:41 AM
  5. [SOLVED] Remove blank rows that aren't really blank (contain unused formulas)
    By painterartist in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2014, 02:01 PM
  6. VBA code to remove rows in case of blank cells
    By GrahamRoss in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2011, 12:02 PM
  7. How to remove blank rows, then insert blank row conditionally, PLUS error proof
    By GTS115 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2009, 11:39 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1