+ Reply to Thread
Results 1 to 2 of 2

Copy rows based on multiple IFs

Hybrid View

  1. #1
    Registered User
    Join Date
    01-12-2020
    Location
    California
    MS-Off Ver
    2016
    Posts
    53

    Question Copy rows based on multiple IFs

    I need help with the following problem. I am not sure how the paid subscription works, but I have $50 points credit to pay for a specialist's help.
    I am looking to build a sub-routine as part of an automatic scheduling for a medical office. Take a look at the attached workbook.
    Sheet1 comes with pre-populated data; the table structure is identical, the table header in row 1 is anonymized. Please keep source table structure the same.
    The VBA needs to analyze data in sheet1 row by row starting with row 2 and skip rows that are hidden. In needs to do that in a loop for a specific amount of times as specified in Sheet2 B4 variable that is entered by the user.

    The following needs to occur in analyzing Sheet1:
    For any unique last name (in D), IF L column contains code D7140 OR D7210 AND IF Column M is between 1 to 8, OR between 9 to 16, or between 17 to 24 or between 25 to 32, THEN COPY row only once to sheet 2 as done manually (shown in red)

    Repeat this loop as many times until the number of rows specified in sheet 2 B4 (variable entered by user) has been copied to Sheet2
    Attached Files Attached Files

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Copy rows based on multiple IFs

    Try this

    Sub Test()
    Dim N As Long
    
    For N = 3 To Sheets("Sheet1").Cells(Rows.Count, 4).End(xlUp).Row
        If Sheets("Sheet1").Rows.RowHeight > 0 Then
            If Sheets("Sheet1").Cells(N, 12) = "D7140" Or Sheets("Sheet1").Cells(N, 12) = "D7210" Then
                If (Sheets("Sheet1").Cells(N, 13) >= 1 And Sheets("Sheet1").Cells(N, 13) <= 8) Or (Sheets("Sheet1").Cells(N, 13) >= 9 And Sheets("Sheet1").Cells(N, 13) <= 16) Or (Sheets("Sheet1").Cells(N, 13) >= 17 And Sheets("Sheet1").Cells(N, 13) <= 24) Or (Sheets("Sheet1").Cells(N, 13) >= 25 And Sheets("Sheet1").Cells(N, 13) <= 32) Then
                    If WorksheetFunction.CountIf(Sheets("Sheet2").Columns(4), Sheets("Sheet1").Cells(N, 4)) < Sheets("Sheet2").Cells(4, 2) Then
                        Sheets("Sheet2").Cells(Rows.Count, 4).End(xlUp).Offset(1, 0) = Sheets("Sheet1").Cells(N, 4)
                        Sheets("Sheet2").Cells(Rows.Count, 4).End(xlUp).Offset(0, 6) = Sheets("Sheet1").Cells(N, 12)
                        Sheets("Sheet2").Cells(Rows.Count, 4).End(xlUp).Offset(0, 7) = Sheets("Sheet1").Cells(N, 13)
                    End If
                End If
            End If
        End If
    Next N
    End Sub
    Martin

+ 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] Copy Multiple Rows Based on Cell Value
    By phelbin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-26-2016, 01:50 PM
  2. Copy rows from multiple sheets based on condition
    By murzilka in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2016, 04:49 PM
  3. How to copy rows based on multiple criteria from one worksheet to another ?
    By Caster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2015, 06:27 AM
  4. Copy rows based off multiple cells
    By Uwantachat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-21-2014, 04:12 PM
  5. Replies: 0
    Last Post: 06-06-2013, 02:03 AM
  6. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM
  7. Copy Multiple Rows Based on Values
    By mmcbride1007 in forum Excel General
    Replies: 0
    Last Post: 06-15-2011, 11:50 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