VBA Destination range is not large enough..

afc171

New Member
Joined
Jan 14, 2017
Messages
32
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

mikerickson

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

afc171

New Member
Joined
Jan 14, 2017
Messages
32
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
414
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

New Member
Joined
Jan 14, 2017
Messages
32

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
414
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,047
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Or
VBA Code:
RgOuput.CurrentRegion.Value = RgOuput.CurrentRegion.Value
 

afc171

New Member
Joined
Jan 14, 2017
Messages
32
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: 4

Watch MrExcel Video

Forum statistics

Threads
1,129,471
Messages
5,636,508
Members
416,919
Latest member
twc2c

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