-
Thanks Mikerickson ,your code does paste the data when run ,but pastes data from all seven source sheets to the respective seven sheets in the target workbook not just the data from the active source sheet to the respective target sheet. Thanks for trying
-
This will restrict itself to copying only from the ActiveSheet.
[vba]If MsgBox("ARE YOU READY TO UPDATE THE HISTORY FILE?", vbYesNo) = vbYes Then
Cancel = True
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim SourceWb As Workbook
Dim TargetWb As Workbook
Dim rngCopy As Range
Application.ScreenUpdating = False
Set SourceWb = Workbooks("Book1.xls")
Set TargetWb = Workbooks("Book2.xls")
Rem remove >>>For Each SourceSheet In SourceWb.Sheets
Set SourceSheet = ActiveSheet: Rem new line <<<<
If SourceSheet.Name Like "Data*" Then 'Additional check here
For Each TargetSheet In TargetWb.Worksheets
If SourceSheet.Name = TargetSheet.Name Then
With TargetSheet.Range("A" & NextEmptyRow(TargetSheet))
.Value = Date
.NumberFormat = "ddd dd mmm yy"
' Add C285 and C286
.Offset(, 1).Value = SourceSheet.Range("C284").Value
.Offset(, 2).Value = SourceSheet.Range("C286").Value
.Offset(, 3).Value = SourceSheet.Range("C288").Value
.Offset(, 4).Resize(1, 46).Value = SourceSheet.Range("G260:AZ260").Value
End With
End If
Next TargetSheet
End If
Rem remove >>>Next SourceSheet
Application.ScreenUpdating = True
End If
End Sub
Function NextEmptyRow(oneSheet As Worksheet) As Long
With oneSheet
NextEmptyRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
End With
End Function [/vba]
-
I may have misunderstood your need.
Did you want the ActiveSheet to be the source or did you want
[VBA]Set SourceSheet = SourceWb.Worksheets("Data" & UCase(Format(Date,"ddd")))[/VBA]
-
A great big thankyou to all .You guys are great