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
 
Untested so not sure exactly what you'll get

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")
   
    rgData.AdvancedFilter xlFilterInPlace, rgCriteria
   
    With rgData.SpecialCells(12)
        rgOutput.Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Again untested

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 = .SpecialCells(12).Value
    End With
or
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
 
        rgData.SpecialCells(12).Copy
        rgOutput.PasteSpecial xlValues
 
Last edited:
Upvote 0
Solution
Compile error:
Variable not defined

Highlights the sub name when you run it on both codes
 
Upvote 0
Hi,​
link your workbook with a files host website and well elaborate what your initial code is trying to achieve​
in order we can post a clean code without the useless but just with the necessary for efficiency …​
 
Upvote 0
That's because I didn't amend your rgOuput to rgOutput when I copied it. Try the amended codes in the post
 
Upvote 0
That's because I didn't amend your rgOuput to rgOutput when I copied it. Try the amended codes in the post

Thanks mate, this one has worked as required!

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

        rgData.SpecialCells(12).Copy
        rgOutput.PasteSpecial xlValues

Thanks alot for your help (y)

Also noticed the actual first problem doesn't show up now either!
 
Upvote 0
You're welcome (remember to put the line Application.CutCopyMode = False after those lines if using that code).
 
Upvote 0

Forum statistics

Threads
1,215,813
Messages
6,127,031
Members
449,355
Latest member
g wiggle

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