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
 

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"
Have you tried seeting
VBA Code:
Application.DisplayAlerts = False
before the .AdvancedFilter line and back to True afterwards.
 
Upvote 0
Have you tried seeting
VBA Code:
Application.DisplayAlerts = False
before the .AdvancedFilter line and back to True afterwards.

That's the ticket, cheers Mike.

Btw not a biggie, but would you know how to copy the data and paste with no formatting to the other sheet?

Thanks anyway.
 
Upvote 0
Looks like you called it rgOuput and not rgOutput so either change all to rgOutput or just rgOuput.clearformats
 
Upvote 0
ah yes good spot, should be output!

ok added clearformats but have run-time error 1004

Method 'AdvancedFilter" of object 'Range' failed
 
Upvote 0
On which line do you get the error. Start at top of code and tap F8 to run through code to see where you get the error

Or maybe something like

RgOuput.currentregion.Copy
RgOutput PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Or
VBA Code:
RgOuput.CurrentRegion.Value = RgOuput.CurrentRegion.Value
 
Upvote 0
Still seems to overwrite the formats, is this correct:

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("A1").CurrentRegion

    rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput.CurrentRegion
    rgOutput.CurrentRegion.Value = rgOutput.CurrentRegion.Value

Screenshot of copied data to Required_Items
Borders and column E overwritten
 

Attachments

  • Screenshot 2021-05-03 at 20.31.36.png
    Screenshot 2021-05-03 at 20.31.36.png
    34.6 KB · Views: 17
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,700
Members
448,293
Latest member
jin kazuya

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