Consulting

Results 1 to 3 of 3

Thread: Empty Row Deletion

  1. #1

    Empty Row Deletion

    Hi All,

    My goal is to create a macro that deletes entire rows that contain no data, save for the first column which is the task name. Depending on which month I need to pull the data from, the number of days in the month will change and the number of tasks will also change, so those will have to be dynamic. I also want the macro to ignore the last two rows, which contains a spacer row and a set of numbers irrelevant to the data. The code that I have would delete rows, but it is for a static data set and won't work if I need to pull a different month.

    Sample Empty Row Deletion.xlsm

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    You can start with this


    Option Explicit
    Sub DeleteEmptyRow()
        Dim iLastRowNum As Long, iRowNum As Long
        
        Application.ScreenUpdating = False
        
        With ActiveSheet
            iLastRowNum = .Cells(.Rows.Count, 1).End(xlUp).Row
        
            For iRowNum = iLastRowNum To 2 Step -1
                If Application.WorksheetFunction.CountA(.Rows(iRowNum)) = 1 Then
                    .Rows(iRowNum).Delete
                End If
            Next
        End With
        Application.ScreenUpdating = True
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Quote Originally Posted by Paul_Hossler View Post
    You can start with this


    Option Explicit
    Sub DeleteEmptyRow()
        Dim iLastRowNum As Long, iRowNum As Long
        
        Application.ScreenUpdating = False
        
        With ActiveSheet
            iLastRowNum = .Cells(.Rows.Count, 1).End(xlUp).Row
        
            For iRowNum = iLastRowNum To 2 Step -1
                If Application.WorksheetFunction.CountA(.Rows(iRowNum)) = 1 Then
                    .Rows(iRowNum).Delete
                End If
            Next
        End With
        Application.ScreenUpdating = True
    End Sub
    Thanks Paul, I think this should be enough to work with!

Posting Permissions

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