Copying a range of column from one sheet to other based on Date in Cloumn A

amandeep99

New Member
Joined
Mar 20, 2023
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am newbie and trying to copy a value of columns from "B" to "BN" from source sheet to destination sheet column starting from "BU", if the value of cell in column "A" matches the yesterday's date.(which is not the last row of sheet)

For this , I have written a below script and facing Runtime error: 1004 copy area size is not matching the paste area

Please help me out of this.

VBA Code:
Public Sub lrowcop()

Dim lastrow As Long
Dim d As Date

Dim wsCopy As Worksheet
Dim wsDest As Worksheet, r As Range

daycount3 = Format(Date - 1, "mmm")
sFolderName = Format(Now - 1, "yyyyMMdd")

Set wsCopy = Workbooks(sFolderName & " - 2 report " & daycount3 & "-2023").Worksheets(daycount3 & "-23")
Set wsDest = Workbooks("Daily bbook").Worksheets("Sheet1")
   

lastrow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "B").End(xlUp).Offset(1).Row

d = [Today()-1]
wsCopy.Activate
For Each c In wsCopy.Range("A1:A" & lastrow)
If d = c.Value Then

      wsDest.Range("A" & lDestLastRow).Value = d
      wsCopy.Activate
      wsCopy.Range("B:BN").Copy
      wsDest.Range("BU" & lDestLastRow).PasteSpecial xlPasteValues
      Application.CutCopyMode = False

End If

Next
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,215,635
Messages
6,125,942
Members
449,275
Latest member
jacob_mcbride

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top