+ Reply to Thread
Results 1 to 11 of 11

Can’t remove blank rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-06-2014
    Location
    The Show Me State
    MS-Off Ver
    Excel 2013
    Posts
    345

    Can’t remove blank rows

    Is there a way to populate sheet2 from sheet1 while removing blank rows?
    Attached Files Attached Files

  2. #2
    Spammer
    Join Date
    01-08-2015
    Location
    Cali, Colombia
    MS-Off Ver
    365
    Posts
    302

    Re: Can’t remove blank rows

    Hi, gz3s36!

    One option with formulae. Blessings!
    Attached Files Attached Files

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Can’t remove blank rows

    On your Expected Results sheet enter formula in A1 and drag formula across and down

    ***Array formula
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER.
    You will know the array is active when you see curly braces { } appear around your formula.
    If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Formula: copy to clipboard
    =IFERROR(INDEX(PROBLEM!A:A,SMALL(IF(PROBLEM!A$1:A$200<>"",ROW(A$1:A$200)),ROWS(A$1:A1))),"")

    For Excel (2010, 2013, 2016) use this regular formula
    Formula: copy to clipboard
    =IFERROR(INDEX(PROBLEM!A:A,AGGREGATE(15,6,ROW(A$1:A$200)/(PROBLEM!A$1:A$200<>""),ROWS(A$1:A1))),"")
    Last edited by AlKey; 12-20-2017 at 02:40 PM.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Forum Contributor
    Join Date
    02-06-2014
    Location
    The Show Me State
    MS-Off Ver
    Excel 2013
    Posts
    345

    Re: Can’t remove blank rows

    Quote Originally Posted by AlKey View Post
    On your Expected Results sheet enter formula in A1 and drag formula across and down

    ***Array formula
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER.
    You will know the array is active when you see curly braces { } appear around your formula.
    If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Formula: copy to clipboard
    =IFERROR(INDEX(PROBLEM!A:A,SMALL(IF(PROBLEM!A$1:A$200<>"",ROW(A$1:A$200)),ROWS(A$1:A1))),"")

    For Excel (2010, 2013, 2016) use this regular formula
    Formula: copy to clipboard
    =IFERROR(INDEX(PROBLEM!A:A,AGGREGATE(15,6,ROW(A$1:A$200)/(PROBLEM!A$1:A$200<>""),ROWS(A$1:A1))),"")
    Is there a way for it to not return 0 for blank cells?

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Can’t remove blank rows

    Yes there is a way
    For array formula
    Formula: copy to clipboard
    =IFERROR(INDEX(PROBLEM!A:A,SMALL(IF((PROBLEM!A$1:A$200<>"")*(PROBLEM!A$1:A$200<>0),ROW(A$1:A$200)),ROWS(A$1:A1))),"")

    For non-array
    Formula: copy to clipboard
    =IFERROR(INDEX(PROBLEM!A:A,AGGREGATE(15,6,ROW(A$1:A$200)/((PROBLEM!A$1:A$200<>"")*(PROBLEM!A$1:A$200<>0)),ROWS(A$1:A1))),"")

  6. #6
    Forum Contributor
    Join Date
    02-06-2014
    Location
    The Show Me State
    MS-Off Ver
    Excel 2013
    Posts
    345

    Re: Can’t remove blank rows

    Just aren't having any luck.

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Can’t remove blank rows

    Quote Originally Posted by gz3s36 View Post
    Just aren't having any luck.
    Luck? This is nothing to do with luck.
    Here is an attached file with two tables. On the left with array formula on the right is non-array.
    Attached Files Attached Files

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,716

    Re: Can’t remove blank rows

    Here is a VBA solution
    Option Explicit
    
    Sub foo()
        Dim s1 As Worksheet, s2 As Worksheet
        Dim i As Long, lr As Long, lr2 As Long
        Set s1 = Sheets("PROBLEM")
        Set s2 = Sheets("EXPECTED RESULT")
        lr = s1.Range("A" & Rows.Count).End(xlUp).Row
        Application.ScreenUpdating = False
        For i = 1 To lr
            lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
            If s1.Range("A" & i) <> "" Then
                s1.Range("A" & i & ":C" & i).Copy s2.Range("A" & lr2 + 1)
            End If
        Next i
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
        MsgBox "complete"
    End Sub
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  9. #9
    Forum Contributor
    Join Date
    02-06-2014
    Location
    The Show Me State
    MS-Off Ver
    Excel 2013
    Posts
    345

    Re: Can’t remove blank rows

    I can't make it work. Either solution.
    Attached Files Attached Files

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,716

    Re: Can’t remove blank rows

    Your issue is that you don't have one consistent column to be evaluated. Suggest you reformat your spreadsheet to have at least one column to evaluate. It would have been helpful from the start if you had presented a sample workbook that was representative of your actual needs. Based upon your original presentation, both solutions would work. Help us to help you in the future by presenting representative samples. We cannot read your mind or see your screen.

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,716

    Re: Can’t remove blank rows

    This code tests for any blank rows. If the entire row is blank, then it copies the data in columns A:S to Sheet2. You have a link to an outside worksheet. This interferes with the code. You may wish to break the link before running the code.
    Option Explicit
    
    Sub foo()
        Dim s1 As Worksheet, s2 As Worksheet
        Dim i As Long, lr As Long, lr2 As Long
        Set s1 = Sheets("Sheet1")
        Set s2 = Sheets("Sheet2")
        lr = s1.Range("A" & Rows.Count).End(xlUp).Row
        Application.ScreenUpdating = False
        For i = 1 To lr
            lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
            If WorksheetFunction.CountA(Range("A" & i & ":S" & i)) <> 0 Then
                s1.Range("A" & i & ":S" & i).Copy s2.Range("A" & lr2 + 1)
            End If
        Next i
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
        MsgBox "complete"
    End Sub

+ 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] 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
  2. [SOLVED] VBA to remove blank rows
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2013, 10:11 AM
  3. Remove blank rows
    By chiragvaya in forum Excel General
    Replies: 6
    Last Post: 12-29-2012, 05:11 AM
  4. Formula to Remove Blank Rows
    By jimmerdean in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-23-2012, 04:25 AM
  5. Remove blank rows
    By JohnsonBeGood in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-10-2011, 01:10 PM
  6. 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
  7. [SOLVED] remove blank rows
    By vernalGreens@gmail.com in forum Excel General
    Replies: 3
    Last Post: 02-20-2006, 11:45 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