VBA Destination range is not large enough..

afc171

Board Regular
Joined
Jan 14, 2017
Messages
70
Office Version
  1. 2019
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,017
Have you tried seeting
VBA Code:
Application.DisplayAlerts = False
before the .AdvancedFilter line and back to True afterwards.
 

afc171

Board Regular
Joined
Jan 14, 2017
Messages
70
Office Version
  1. 2019
Platform
  1. Windows
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.
 

rhombus4

Active Member
Joined
May 26, 2010
Messages
446
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Looks like you called it rgOuput and not rgOutput so either change all to rgOutput or just rgOuput.clearformats
 

afc171

Board Regular
Joined
Jan 14, 2017
Messages
70
Office Version
  1. 2019
Platform
  1. Windows

ADVERTISEMENT

ah yes good spot, should be output!

ok added clearformats but have run-time error 1004

Method 'AdvancedFilter" of object 'Range' failed
 

rhombus4

Active Member
Joined
May 26, 2010
Messages
446
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,119
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Or
VBA Code:
RgOuput.CurrentRegion.Value = RgOuput.CurrentRegion.Value
 

afc171

Board Regular
Joined
Jan 14, 2017
Messages
70
Office Version
  1. 2019
Platform
  1. Windows
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: 6

Watch MrExcel Video

Forum statistics

Threads
1,132,900
Messages
5,655,863
Members
418,249
Latest member
JOYADA

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
Top