+ Reply to Thread
Results 1 to 4 of 4

VBA macro to delete all empty rows and columns

Hybrid View

  1. #1
    Registered User
    Join Date
    03-27-2015
    Location
    Franklin Lakes, NJ
    MS-Off Ver
    Excel 2010
    Posts
    6

    VBA macro to delete all empty rows and columns

    Hello,

    I'm in need of a macro that will delete all the empty lines and columns within the spreadsheet. I need all empty lines after (and including) line 17 and all empty columns after (and including) Column V. I want to be able to add this to an existing macro.

    edit: Also, the deleting would have to be done before anything else withing the existing macro.

    The manual way I would do this would be to select the first empty line after the data (Ctrl+Shift+arrow key down), right click the spreadsheet and click delete. Same process for the columns. Then I would run the macro below


    Thank you
    Last edited by specialist1; 04-09-2015 at 02:06 PM. Reason: meant to write columns instead of rows

  2. #2
    Registered User
    Join Date
    03-27-2015
    Location
    Franklin Lakes, NJ
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to delete all empty rows and columns

    Here is the macro I'm currently working with, just need the above concept added to the beginning

    Sub CreateRebateFile()
    
    Const TAB_DELIMITED = 3
    Const EXCEL_WORKSHEET = 1
    
    Dim msgResponse As Variant
    
    On Error GoTo CreateRebateFile_Error
    
    
    '** Save the workbook before creating the individual files
    If ActiveWorkbook.Saved = False Then
        msgResponse = MsgBox("Do you want to Save this Excel Workbook? (Recommended)", _
                vbOKCancel + vbDefaultButton1 + vbQuestion, "Rebate File for SAP")
        If msgResponse = vbOK Then
            Application.Dialogs(xlDialogSaveAs).Show "", EXCEL_WORKSHEET
        End If
    End If
    
    For Each Worksheet In Worksheets
    
    Worksheet.Select
    
    '** Offer to Save the Excel File
    If Range("Customer_Number").Value > " " Then
        
        If Range("Period_FROM").Value > " " And _
           Range("Period_To").Value > " " Then
            
                
                If Range("START_CELL").Value > " " Then
        
                    msgResponse = MsgBox("Would you like to Create the SAP Upload File for Worksheet: " _
                        & Worksheet.Name & " ?", _
                        vbOKCancel + vbDefaultButton1 + vbQuestion, _
                        "Rebate File for SAP")
                    If msgResponse = vbOK Then
                       Application.Dialogs(xlDialogSaveAs).Show "", TAB_DELIMITED
                    End If
    
                Else
        
                    MsgBox "No Claims entered in Worksheet: " & Worksheet.Name, _
                        vbOKCancel + vbExclamation, "Rebate Save Error"
                    Range("START_CELL").Select
                End If
        
            Else
        
            MsgBox "Rebate Period Incomplete or Invalid for Worksheet: " & Worksheet.Name, _
                vbOKCancel + vbExclamation, "Rebate Save Error"
            Range("Period_FROM").Select
        End If
    Else
        
        MsgBox "Customer Number Missing in Worksheet: " & Worksheet.Name, _
        vbOKCancel + vbExclamation, "Rebate Save Error"
        Range("Customer_Number").Select
    End If
        
    Next
        
    Exit Sub
    
    CreateRebateFile_Error:
    
        
        MsgBox "UnExpected Error Occurred During Conversion: " & vbCrLf & _
                "#" & Err.Number & ": " & Err.Description, vbOKOnly + vbExclamation, "Rebate File for SAP"
         
        Err.Clear
         
        Exit Sub
    
    
    
    End Sub
    Last edited by specialist1; 04-09-2015 at 02:01 PM.

  3. #3
    Registered User
    Join Date
    03-27-2015
    Location
    Franklin Lakes, NJ
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VBA macro to delete all empty rows and columns

    Essentially there are no blank rows/columns within the data. The blank rows/columns are all outside the data range. I need them deleted because our SAP system still recognizes them as lines. Thousands and thousands of lines being processed for no reason.

    This is the recorded macro from how I delete the rows manually.
    Sub testdelete()
    '
    ' testdelete Macro
    '
    
    '
        Rows("34:34").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Delete Shift:=xlUp
    End Sub
    Does anyone have any ideas how to have excel only delete the empty ones?

  4. #4
    Registered User
    Join Date
    03-27-2015
    Location
    Franklin Lakes, NJ
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VBA macro to delete all empty rows and columns

    ****ISSUE SOLVED

    -admin please close the thread

+ 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. 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
  2. [SOLVED] Delete rows when two columns are empty
    By Musoguy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-29-2013, 09:00 AM
  3. how to delete empty rows or columns only
    By tallercheetah in forum Excel General
    Replies: 3
    Last Post: 02-02-2012, 10:44 AM
  4. Find empty columns, rows and delete
    By ebe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2010, 10:00 AM
  5. Delete rows with empty cells in columns B&C
    By Richard in forum Excel General
    Replies: 3
    Last Post: 03-17-2006, 08:20 PM

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