+ Reply to Thread
Results 1 to 5 of 5

Need to modify code to skip blank rows and headings

Hybrid View

missit Need to modify code to skip... 02-01-2015, 06:31 PM
berlan Re: Need to modify code to... 02-01-2015, 07:23 PM
missit Re: Need to modify code to... 02-05-2015, 08:18 PM
skywriter Re: Need to modify code to... 02-02-2015, 02:22 AM
AB33 Re: Need to modify code to... 02-02-2015, 05:26 AM
  1. #1
    Registered User
    Join Date
    10-13-2010
    Location
    Colorado Springs, CO
    MS-Off Ver
    Excel 2010
    Posts
    55

    Need to modify code to skip blank rows and headings

    Hi,

    I need to modify this code so that it will skip the headings as well as the blank rows below the headings.

    Sub Billing()
    
        Dim Data    As Variant
        Dim DstWks  As Worksheet
        Dim LastRow As Long
        Dim n       As Long
        Dim NextRow As Long
        Dim SrcRng  As Range
        Dim SrcWks  As Worksheet
    
            'UnProtectall
            
            Set DstWks = ThisWorkbook.Sheets("Billing Summary")
            
                NextRow = DstWks.Cells(Rows.Count, "A").End(xlUp).Row
                NextRow = IIf(NextRow < 3, 3, NextRow + 1)
                
                For Each SrcWks In ThisWorkbook.Worksheets
                    Select Case SrcWks.Name
                        Case "Audit Summary", "Accuracy Report Group", "Master Provider List", "Instructions", "Billing Temp", "Audit Temp", "Code_Table", "Billing Summary"
                            ' Skip these worksheets
                        Case Else
                            Set SrcRng = SrcWks.Range("A20:i90")
                              LastRow = SrcRng.Cells(SrcRng.Rows.Count, SrcRng.Column + 1).End(xlUp).Row
                            Set SrcRng = SrcRng.Resize(RowSize:=LastRow - SrcRng.Row + 1)
                            
                            ReDim Data(1 To SrcRng.Rows.Count, 1 To 10)
                    
                                For n = 1 To SrcRng.Rows.Count
                                    Data(n, 1) = SrcWks.Range("c4")
                                    Data(n, 2) = SrcRng.Item(n, 2)
                                    Data(n, 3) = SrcRng.Item(n, 3)
                                    'Data(n, 4) = Empty
                                    Data(n, 4) = SrcRng.Item(n, 4)
                                    Data(n, 5) = SrcRng.Item(n, 5)
                                    Data(n, 6) = SrcRng.Item(n, 6)
                                    Data(n, 7) = SrcRng.Item(n, 7)
                                    Data(n, 8) = Empty
                                    Data(n, 9) = SrcRng.Item(n, 9)
                                Next n
                                
                            DstWks.Cells(NextRow, "A").Resize(n - 1, UBound(Data, 2)).Value = Data
                            NextRow = NextRow + n - 1
                    End Select
                    
                    
                Next SrcWks
                
            'ProtectAll
            
    End Sub
    I have attached a workbook Working copy of Billing Summary.xlsmto show how the data is setup. Currently it includes the headings (Office/Outpatient, Hospital and Re-Audit) with all the data below those headings for each of the physicians, however, I need it to skip those headings and the blank rows below them and only extract actual data.

    thanks for the help

    Missit
    Last edited by JBeaucaire; 02-06-2015 at 10:37 AM. Reason: Merged threads

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Need to modify code to skip blank rows and headings

    Hi Missit,

    try if this works for you:
    Sub Billing2()
    
        Dim Data() As Variant
        Dim a As Range, r As Range, i As Long
        Dim SrcWks As Worksheet
        Dim DstWks As Worksheet: Set DstWks = ThisWorkbook.Sheets("Billing Summary")
    
        For Each SrcWks In ThisWorkbook.Worksheets
            Select Case SrcWks.Name
                Case "Audit Summary", "Accuracy Report Group", "Master Provider List", "Instructions", "Billing Temp", "Audit Temp", "Code_Table", "Billing Summary"
                    ' Skip these worksheets
                Case Else
                    With SrcWks.Range("A20:I90")
                        ReDim Data(1 To Application.CountA(Intersect(.Columns(3).SpecialCells(2, 1), .Cells)), 1 To 10)
                        For Each a In .Columns(3).SpecialCells(2, 1).Areas  'loops through each area with DoB defined
                            For Each r In Intersect(a.EntireRow, .Cells).Rows   'loops through each row of each area
                                If Application.CountA(r) > 1 Then
                                    i = i + 1
                                    Data(i, 1) = SrcWks.Range("C4").Value
                                    Data(i, 2) = r.Cells(2)
                                    Data(i, 3) = r.Cells(3)
                                    Data(i, 4) = r.Cells(4)
                                    Data(i, 5) = r.Cells(5)
                                    Data(i, 6) = r.Cells(6)
                                    Data(i, 7) = r.Cells(7)
                                    Data(i, 9) = r.Cells(9)
                                End If
                            Next r
                        Next a
                        DstWks.Range("A" & Application.Max(3, DstWks.Cells(Rows.Count, "A").End(xlUp).Row)).Resize(i, 10).Value = Data  'destination
                        i = Empty   'clear before moving to next sheet
                    End With
            End Select
        Next SrcWks
    
    End Sub
    Best,
    Johan

  3. #3
    Registered User
    Join Date
    10-13-2010
    Location
    Colorado Springs, CO
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Need to modify code to skip blank rows and headings

    Quote Originally Posted by berlan View Post
    Hi Missit,

    try if this works for you:
    Sub Billing2()
    
        Dim Data() As Variant
        Dim a As Range, r As Range, i As Long
        Dim SrcWks As Worksheet
        Dim DstWks As Worksheet: Set DstWks = ThisWorkbook.Sheets("Billing Summary")
    
        For Each SrcWks In ThisWorkbook.Worksheets
            Select Case SrcWks.Name
                Case "Audit Summary", "Accuracy Report Group", "Master Provider List", "Instructions", "Billing Temp", "Audit Temp", "Code_Table", "Billing Summary"
                    ' Skip these worksheets
                Case Else
                    With SrcWks.Range("A20:I90")
                        ReDim Data(1 To Application.CountA(Intersect(.Columns(3).SpecialCells(2, 1), .Cells)), 1 To 10)
                        For Each a In .Columns(3).SpecialCells(2, 1).Areas  'loops through each area with DoB defined
                            For Each r In Intersect(a.EntireRow, .Cells).Rows   'loops through each row of each area
                                If Application.CountA(r) > 1 Then
                                    i = i + 1
                                    Data(i, 1) = SrcWks.Range("C4").Value
                                    Data(i, 2) = r.Cells(2)
                                    Data(i, 3) = r.Cells(3)
                                    Data(i, 4) = r.Cells(4)
                                    Data(i, 5) = r.Cells(5)
                                    Data(i, 6) = r.Cells(6)
                                    Data(i, 7) = r.Cells(7)
                                    Data(i, 9) = r.Cells(9)
                                End If
                            Next r
                        Next a
                        DstWks.Range("A" & Application.Max(3, DstWks.Cells(Rows.Count, "A").End(xlUp).Row)).Resize(i, 10).Value = Data  'destination
                        i = Empty   'clear before moving to next sheet
                    End With
            End Select
        Next SrcWks
    
    End Sub
    Best,
    Johan

    Hi, I tried sending you an answer on this, but I don't know where it went. It works fine, except that I forgot to mention that some of the pages may be blank. When that happens, the code breaks. Is there a way we can skip those pages that don't have any data in them?

    Thanks so much for all your help.

    Carole

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Cool Re: Need to modify code to skip blank rows and headings

    Rather than mess with your code why not just clean up the billing summary sheet.
    I wrote this sub and it tested okay. Since you have that cool button where you can repopulate the billing summary sheet you can test it out for yourself.

    Good Luck!


    Sub CleanUpBillingSummary()
    
    Dim lr As Long
    Dim ws As Worksheet
    Dim c As Long
    Dim NotDesired()
    
    Application.ScreenUpdating = False
    
    NotDesired = Array("Office/OutPatient", "TOTALS", "Hospital", "Re-Audit")
    
    Set ws = Worksheets("Billing Summary")
    ws.Activate
    lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
    
    With ws
        For c = lr To 3 Step -1
                If UBound(Filter(NotDesired, .Cells(c, 2).Value)) = 0 Or .Cells(c, 2).Value = "" Then
                    .Rows(c).EntireRow.Delete
                End If
        Next c
    End With
    
    Application.ScreenUpdating = True
        
    End Sub

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need to modify code to skip blank rows and headings

    For skipping the heading, change this line

     For n = 1 To SrcRng.Rows.Count
    
    
    INTO
    
     For n = 2 To SrcRng.Rows.Count

+ 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] Need to add skip blank cells to my code
    By Garbology in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-12-2014, 03:45 AM
  2. Need help to make VBA to skip rows that are blank
    By vnzerem in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2013, 05:55 PM
  3. [SOLVED] Skip Section of Code if Filter Returns a Blank
    By tamiso2311 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 12:53 AM
  4. Skip Blank rows
    By Bmxerdude2087 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2012, 11:09 PM
  5. skip blank rows when pasting formulas
    By Newsgal in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 AM

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