+ Reply to Thread
Results 1 to 10 of 10

Macro that removes empty rows within a table

Hybrid View

airedale360 Macro that removes empty rows... 08-10-2016, 12:14 PM
Bernie Deitrick Re: Macro that removes empty... 08-10-2016, 01:13 PM
airedale360 Re: Macro that removes empty... 08-10-2016, 01:34 PM
MarvinP Re: Macro that removes empty... 08-10-2016, 01:21 PM
airedale360 Re: Macro that removes empty... 08-10-2016, 01:37 PM
Bernie Deitrick Re: Macro that removes empty... 08-10-2016, 03:17 PM
airedale360 Re: Macro that removes empty... 08-10-2016, 05:37 PM
Bernie Deitrick Re: Macro that removes empty... 08-10-2016, 06:00 PM
airedale360 Re: Macro that removes empty... 08-10-2016, 07:13 PM
Bernie Deitrick Re: Macro that removes empty... 08-10-2016, 07:24 PM
  1. #1
    Registered User
    Join Date
    06-03-2013
    Location
    US
    MS-Off Ver
    Excel 2016
    Posts
    41

    Post Macro that removes empty rows within a table

    Hello,

    I have a Macro that runs once a week from data off a csv file. There is no set amount of data that is pulled from the csv. its whatever was processed that week. the csv file could have 800 rows or up to 1000 rows of data. here is my issue. I formatted my macro to create a table so i can add specific formulas to the cells to eliminate drag the formulas down. once done i copy/paste with values to remove the formulas. once that step is done this entire sheet is copied into a new excel workbook away from the macro for more manipulation.

    When i filter Column A to remove blanks in the table it copies over just the filtered data and makes new issues on the next workbook. i added a recording in STEP6_1 to filter by blanks and clear content, but now if my data goes to row 545 and deletes the rest. even though i pulled 735 rows from the csv.

    i try go to special to locate blanks instead but is does not consider the empty cells in the table as blanks, so i cant use that in my recording either.

    here is what i need.

    After i have the entire table pasted with values, the recording would then search the last cell in column A that has actual data and delete everything below. if creating a table that grows or shrinks is best let me know. i am still new to coding so bare with me on my macros.

    here is my macro. this happens in STEP6_1
    macro.txt

    running office 2016
    Last edited by airedale360; 08-10-2016 at 12:59 PM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Macro that removes empty rows within a table

    Make your table the size of your data by changing

    Sub STEP2()
    '
    ' STEP2 Macro
    '
    
    '
        Range("A6:M7").Select
        ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$6:$M$7"), , xlYes).Name = _
            "Table1"
        Range("Table1[#All]").Select
        ActiveSheet.ListObjects("Table1").TableStyle = ""
        ActiveSheet.ListObjects("Table1").Resize Range("$A$6:$M$800")
        Range("A6:M7").Select
    End Sub
    to

    Sub STEP2()
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("A6", Cells(Cells(Rows.Count, "A").End(xlUp), "M")), , xlYes).Name = _
            "Table1"
    End Sub
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    06-03-2013
    Location
    US
    MS-Off Ver
    Excel 2016
    Posts
    41

    Re: Macro that removes empty rows within a table

    HI Bernie,

    I just ran your code. what is did was create a large table down to row 80115 it wrote in my formulas but did not carry the data over from "RAW". when i double clicked my one row in the table that has data is did auto-fill but did not adjust the table size to row 543. thoughts?
    Last edited by airedale360; 08-10-2016 at 01:40 PM.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,372

    Re: Macro that removes empty rows within a table

    Hi Airedale,

    Your problem sounds like a prefect one for learning and using Power Query. It can easily remove blank rows from a csv file for each new one your get daily or weekly.

    It is a Microsoft Add-In for 2010 and 2013 and comes with 2016 but renamed to "Get & Transform".
    Install it from
    https://www.microsoft.com/en-us/down...6-af05a940c4d4

    http://www.bing.com/videos/search?q=...20D2&FORM=VIRE
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Registered User
    Join Date
    06-03-2013
    Location
    US
    MS-Off Ver
    Excel 2016
    Posts
    41

    Re: Macro that removes empty rows within a table

    Hi Marvin.

    the add-on is a great option if I am the one running the reports, but I am not. I created this Macro for someone else to use. this means i have to account for multiple human factors on how they work in excel. this is the reason i use Paste with value to eliminate a step for them
    Last edited by airedale360; 08-10-2016 at 02:58 PM.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Macro that removes empty rows within a table

    It is hard to trouble shoot with just code - if your sheet at the time of the macro running only has one block of data starting in cell A1, then is should have only found the 500 or so entries that you have.

    How about this:
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("A6").CurrentRegion, , xlYes).Name = _
            "Table1"
    This assumes that your headers are in row 6, and the table is separated from other entries by at least one entirely blank row and column.

  7. #7
    Registered User
    Join Date
    06-03-2013
    Location
    US
    MS-Off Ver
    Excel 2016
    Posts
    41

    Re: Macro that removes empty rows within a table

    So how its processed. The header is always on row 6. i apply formulas to each cell A7:M7 in STEP1. the in STEP2 I highlight A6:M7 and convert to a table. then resize the table to 800 rows. the data from my RAW sheet auto-fills all the way down to row 800. this week only 546 rows from "RAW" were downloaded from the csv, but my table in "clean Up" carries the formula all the way to row 800. i need the table to resize up to row 546 for this week but next week it may need to shrink to row 650.

    the new code you provided now only creates a table size of A6:M7.

    if this is a factor some of my data from the csv do not have something in each cell. some are blank for that row.

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Macro that removes empty rows within a table

    Where are your data if you have formulas in the new table?

    You need to count your data wherever it is and use that count to adjust your table size:
    lngDataCount = Worksheets("Sheet With Data").Cells(Rows.Count,"A").End(xlUp).Row
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("A6:M" & lngDataCount), , xlYes).Name = _
            "Table1"

  9. #9
    Registered User
    Join Date
    06-03-2013
    Location
    US
    MS-Off Ver
    Excel 2016
    Posts
    41

    Re: Macro that removes empty rows within a table

    that worked. i have to make this the very first thing the macro does. thank you!

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Macro that removes empty rows within a table

    Great - just make sure that you adjusted for the 6 row offset of your table. For example, if your RAW sheet starts with data in row 1, and your first row of formulas is in row 7, then you need to add 6 to the count of rows.
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("A6:M" & lngDataCount + 6), , xlYes).Name = _
            "Table1"

+ 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. [SOLVED] Go To Last Used Row of Table, Delete all empty rows below it.
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-03-2014, 04:00 PM
  2. Delete Empty Rows and empty columns from the word table
    By mvneema in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2014, 10:51 AM
  3. [SOLVED] Macro that removes rows based on frequency and copies part of the row to a new sheet
    By njmiller31 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-28-2012, 05:32 PM
  4. Applying autofilter removes rows from sight outside of table
    By mcneill_garr in forum Excel General
    Replies: 5
    Last Post: 08-15-2011, 02:32 PM
  5. Deleting Empty rows in table
    By grey_hair in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-22-2011, 08:19 AM
  6. VBA that removes duplicate rows
    By Blindbert in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-21-2007, 12:32 PM
  7. Pivot Table hiding row removes from row !
    By Fullam in forum Excel General
    Replies: 1
    Last Post: 04-14-2006, 07:50 PM

Tags for this Thread

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