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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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