VBA Destination range is not large enough..

afc171

Board Regular
Joined
Jan 14, 2017
Messages
143
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I am coping a selection of data to another sheet but keep getting message that the destination range is not large enough to accommodate all copied rows ?

I click Yes and it copies over fine but is there a way to ignore the message or automatically click Yes?

VBA Code:
    Dim rgData As range, rgCriteria As range, rgOuput As range
    
    Set rgData = ThisWorkbook.Worksheets("LCStock").range("A5").CurrentRegion
    Set rgCriteria = ThisWorkbook.Worksheets("LCStock").range("F3").CurrentRegion
    Set rgOuput = ThisWorkbook.Worksheets("Required_Items").range("A2").CurrentRegion

    rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOuput

Thank you
 
My answer was in response to post 8 (my fault should have specified it).
What was the exact code you used when you got the below?
ah yes good spot, should be output!

ok added clearformats but have run-time error 1004

Method 'AdvancedFilter" of object 'Range' failed
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
My answer was in response to post 8 (my fault should have specified it).
What was the exact code you used when you got the below?

it was this line..

VBA Code:
    rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput.ClearFormats
 
Upvote 0
It should be a separate line
VBA Code:
rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput
rgOutput.ClearFormats
 
Upvote 0
It should be a separate line
VBA Code:
rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput
rgOutput.ClearFormats

Doesn't seem to work, for some reason still overwrites the formatting on the other sheet.
 
Upvote 0
Ok, we'll start from scratch. What do you get with

VBA Code:
  Dim rgData As Range, rgCriteria As Range, rgOutput As Range
   
    Set rgData = ThisWorkbook.Worksheets("LCStock").Range("A5").CurrentRegion
    Set rgCriteria = ThisWorkbook.Worksheets("LCStock").Range("F3").CurrentRegion
    Set rgOutput = ThisWorkbook.Worksheets("Required_Items").Range("A2")

    With rgData
        rgOutput.Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
Upvote 0
ok, that seems to copy everything from LCStock and duplicate it into Required_Items, so does not copy only the filtered items.

Although, it does not overwrite the formatting in Required_Items!
 
Upvote 0
Then I think that your best option is to do a filter in place and copy that

VBA Code:
    Dim rgData As Range, rgCriteria As Range, rgOutput As Range
    
    Set rgData = ThisWorkbook.Worksheets("LCStock").Range("A5").CurrentRegion
    Set rgCriteria = ThisWorkbook.Worksheets("LCStock").Range("F3").CurrentRegion
    Set rgOutput = ThisWorkbook.Worksheets("Required_Items").Range("A2")
    
    rgData.AdvancedFilter xlFilterInPlace, rgCriteria
    
    With rgData
        rgOutput.Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
Upvote 0
That seems to filter the data, but also copying everything over for some reason
 
Upvote 0

Forum statistics

Threads
1,215,811
Messages
6,127,020
Members
449,351
Latest member
Sylvine

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