Results 1 to 9 of 9

Coding works for single criteria, but how would you modify it for several criteria?

Threaded View

  1. #1
    Registered User
    Join Date
    03-15-2024
    Location
    California
    MS-Off Ver
    365
    Posts
    18

    Unhappy Coding works for single criteria, but how would you modify it for several criteria?

    Hello, I've attempted to modify this code (See below) to check a cell in Worksheet "Execution Template" column #9 (I) for multiple criteria (a total of 5 different ones) then copy specific cells in that row;before going to the next cell. After copying the specific cells in the row that met the criteria in column #9 (I) they would be pasted in sequence into worksheet "TEST" (Gantt Chart). Unfortunately, I don't possess the skills to be successful at such an endeavor. My attempts have produced the code going through the complete loop for a single criteria then copying that row's specific cells before going to the next criteria and repeating the same process. This unfortunately has resulted in the pasting of the cells out of sequence. This makes it impossible to follow any work that belongs to the same JOB # on the Gantt Chart. I would appreciate any and all assistance on this issue. Thank you.

    Sub CopyPaste()
    
        Dim SourceData As Worksheet
        Dim Dashboard As Worksheet
        Dim searchString As String
        Dim lastSourceRow As Long
        Dim startSourceRow As Long
        Dim lastTargetRow As Long
        Dim sourceRowCounter As Long
        Dim columnToEval As Long
        Dim columnCounter As Long
        Dim columnsToCopy As Variant
        Dim columnsDestination As Variant
        
        Set SourceData = ThisWorkbook.Worksheets("Source Data")
        Set Dashboard = ThisWorkbook.Worksheets("Dashboard")
        
        columnsToCopy = Array(7, 8, 11)
        columnsDestination = Array(2, 3, 4)
        
        searchString = "New"
        startSourceRow = 3
        columnToEval = 45
        
        lastTargetRow = Dashboard.Cells(Dashboard.Rows.Count, 1).End(xlUp).Row 'move this out of the loop
        lastSourceRow = SourceData.Cells(SourceData.Rows.Count, 1).End(xlUp).Row
        
        For sourceRowCounter = startSourceRow To lastSourceRow
            If SourceData.Cells(sourceRowCounter, columnToEval).Value = searchString Then
                
                For columnCounter = 0 To UBound(columnsToCopy)
                    Dashboard.Cells(lastTargetRow, columnsDestination(columnCounter)).Offset(1, 0).Value = _
                          SourceData.Cells(sourceRowCounter, columnsToCopy(columnCounter)).Value
                Next columnCounter
                lastTargetRow = lastTargetRow + 1 'next destination row
            End If
        Next sourceRowCounter
        
        SourceData.Activate
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Coding works for WORD but not POWERPOINT, how should i modify it?
    By reniip in forum PowerPoint Formatting & General
    Replies: 1
    Last Post: 10-09-2023, 03:05 AM
  2. Single Criteria Index Match with concatenated criteria NOT WORKING
    By hassanleo1987 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 04-26-2017, 12:28 AM
  3. Countifs with multiple criteria in single criteria range
    By SUHAS KARHADKAR in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 12-01-2016, 10:55 AM
  4. Countifs with multiple criteria in single criteria range
    By MCP313 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-01-2016, 03:51 AM
  5. Replies: 0
    Last Post: 05-02-2016, 07:59 AM
  6. [SOLVED] Counting cells that meet multiple single criteria as variable criteria
    By BillBasil in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-01-2016, 10:33 AM
  7. Return dates that match a single criteria (a countif criteria)
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2014, 12:43 PM

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