Resize property when transferring data over

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
880
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am running into an issue applying the resize property. I recently started learning about it and I have tried so many variations on the below but its not working. Could someone let me know what I am doing wrong? It for some reason is coming with the last 9 records from A to L all as #N/A. Previously I was copying the data and pasting but I am working with a lot of data and testing performance improvements by moving to an approach more like the below.

VBA Code:
'after execution copy from source and paste into relative sheet applying formulas
With WsSec
lastRow = .Cells(WsSec.rows.count, "A").End(xlUp).row 'find the maximum row
End With

On Error Resume Next
    If Not Worksheets(SheetName).Name = WsCus.Range("FILTER").Offset(i, -1).Value Then Worksheets.Add.Name = WsCus.Range("FILTER").Offset(i, -1).Value
On Error GoTo 0

With Worksheets(SheetName)
        .Range("A1:L" & lastRow).Resize(lastRow).Value = WsSec.Range("A10:L" & lastRow).Value
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It is because you're only resizing the rows and not the columns. When omitting the second parameter, its default value is 1. There are 12 columns from A to L.

Excel Formula:
 .Range("A1").Resize(lastRow-10+1,12).Value = WsSec.Range("A10:L" & lastRow).Value

Also lastRow is not the number of rows you're pasting. You're pasting from row 10 to last row so the number of rows needed to resize is lastRow - 10 +1.
 
Upvote 0
So then in theory something like this should work?

VBA Code:
.Range("A1:L" & lastRow).Resize(lastRow - 10).Value = WsSec.Range("A10:L" & lastRow).Value
 
Upvote 0
If you're going to call the whole range, you don't need to resize.
 
Upvote 0
I only wish to bring over all used data from A10 to L onto that sheet starting on A1
 
Upvote 0
Did you try the code in #2? Do you understand it?
 
Upvote 0
Not yet but I will. I tried #3 and worked but your point about not needing resize has me thinking do I need it? I don’t want to cause performance issues because I loop through that code for 25+ sheets
 
Upvote 0
Another option:
VBA Code:
With WsSec.Range("A10:L" & lastRow)
    Worksheets(SheetName).Range("A1").Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
 
Upvote 0
Solution
Both those results work as does the one I sent in post #3. Timing almost seems the same. is one more efficient than the other or it doesn't really matter? What is proper coding method?
 
Upvote 0
You're resizing more than what you need it to be. If there's data already there, you'll overwrite it. I would recommend something like Akuini's, more dynamic.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

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