Here is the entire code I am using. Your code is at the top followed by the code below the double line that does work for the copy and paste. Interestingly, if I comment out the Next WS line at the bottom of the code (as shown below) I get the first timesheet read and the values pasted correctly but it does not get to the next WS. If I comment out the Next WS in your code at the top, I get the MsgBox "there is no sheet with that pattern". Really got me scratching my head.
Sub CopyValuesBetweenWorksheets()
Dim sourceWS As Worksheet
Dim targetWS As Worksheet
Dim ws As Worksheet
Dim WSName As String
Dim wsDailySummary As Worksheet
Dim sourceWSName As String
For Each ws In ThisWorkbook.Worksheets
If ws.Name Like "???_?????" Then
sourceWSName = ws.Name
Exit For
End If
Next ws
If sourceWSName = "" Then
MsgBox "There is no sheet with that pattern."
Else
Set sourceWS = ThisWorkbook.Worksheets(sourceWSName)
Set targetWS = ThisWorkbook.Worksheets("Daily Summary")
End If
Set sourceWS = ThisWorkbook.Worksheets(sourceWSName)
----------------------------------------------------------------------------------------
' Check the date entered on the Daily Summary against the date on the first row of the timesheets for a match
Dim datevalueDailySummary As Date
Dim datevaluesourcews As Date
' Set references to the worksheets
Set wsDailySummary = ThisWorkbook.Worksheets("Daily Summary")
'Set sourceWS = ThisWorkbook.Worksheets(sourceWSName)
Set targetWS = ThisWorkbook.Worksheets("Daily Summary")
' Get the dates from the specified cells
datevalueDailySummary = wsDailySummary.Range("N14").Value
datevaluesourcews = sourceWS.Range("C18").Value
' Compare the dates
If datevalueDailySummary = datevaluesourcews Then
' Fill in the first row on the Daily Summary Sheet
' Copy values from specific cells in the source sheet to specific cells in the target sheet
targetWS.Range("B21").Value = sourceWS.Range("f4").Value
targetWS.Range("c21").Value = sourceWS.Range("m4").Value
targetWS.Range("d21").Value = sourceWS.Range("q1").Value
Dim lastRow As Long
Dim i As Long
' Find the last row with data in the source worksheet
lastRow = 32 'sourcews.Cells(sourcews.Rows.Count, "C").End(xlUp).Row
' Loop through each row in the source worksheet
For i = 18 To lastRow
' Check if the date value in column C matches datevalueDailySummary
If sourceWS.Cells(i, 3).Value = datevalueDailySummary Then
' Copy relevant data to the next available row in the target worksheet
targetWS.Cells(targetWS.Rows.Count, "F").End(xlUp).Offset(1, 0).Value = sourceWS.Cells(i, 5).Value
targetWS.Cells(targetWS.Rows.Count, "G").End(xlUp).Offset(1, 0).Value = sourceWS.Cells(i, 6).Value
targetWS.Cells(targetWS.Rows.Count, "H").End(xlUp).Offset(1, 0).Value = sourceWS.Cells(i, 7).Value
targetWS.Cells(targetWS.Rows.Count, "I").End(xlUp).Offset(1, 0).Value = sourceWS.Cells(i, 8).Value
' Check other conditions and update targetws.Range("E") accordingly
If sourceWS.Range("AD3").Value Or sourceWS.Range("AD4").Value = True Then
targetWS.Cells(targetWS.Rows.Count, "E").End(xlUp).Offset(1, 0).Value = "Pickup/SUV"
End If
targetWS.Cells(targetWS.Rows.Count, "K").End(xlUp).Offset(1, 0).Value = sourceWS.Cells(i, 21).Value
targetWS.Cells(targetWS.Rows.Count, "L").End(xlUp).Offset(1, 0).Value = sourceWS.Cells(i, 22).Value
End If
Next i
End If
'Next ws
End Sub[/CODE]