paste value with filter criteria

olieph

New Member
Joined
Jun 4, 2008
Messages
19
Hi all,
i created the macro like this:

Sheets("MRR_Log").Select
'Selection.AutoFilter Field:=7
Range("Q2").Select
Selection.AutoFilter Field:=18, Criteria1:="Open"
Range("A2:aj2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy Workbooks("Template MRR Log.xls").Sheets("Uncompleted Data").Cells(Rows.Count, _
1).End(xlUp).Offset(1, 0)

to copy some data with criteria "open" on it and paste it to sheets uncompleted data on the first blank row.
but that macro give me a big file when there's no data with "open" it will paste the blank data until row 65536 (so it just copying the format of the data).
How to avoid that and just to paste special value for any data with criteria "open" on it (the data contains some formula and lookup).
I hope it's clear enough.

thanks for your help!
ovie
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi

You should only get problems if your A column had values all the way down to 65536 - and I'm assuming this isnt the case?

Try:

Code:
With Sheets("MRR_Log")
  .Range("Q2").AutoFilter Field:=18, Criteria1:="Open"
  .Range("A2:aj" & .Cells(.Rows.Count,"A").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy
End With
Workbooks("Template MRR Log.xls").Sheets("Uncompleted Data").Cells(Rows.Count, _
1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
 

olieph

New Member
Joined
Jun 4, 2008
Messages
19
Hi Richard,
thank you so muuchhhhh for the reply!

it happens because i have no data with the filtered criteria at this time.so the macro select the rest of the rows.

btw,thanks for the formula, it works like a charm (if i have the data with the filtered criteria). If i didn't have any data, the macro will copy the headline.

with "End(xlUp).Row", it didn't select the rest of the rows with no data on it! :)

i'm so happy! thanks!
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
To get around instances where there is no data I always like to utilise two range references: one with the entire data table (ie including the header row) and one with just data (exc header row):

Code:
'Data with Header row:
Set rIncHdr = Range("A1:Z" & Cells(Rows.Count,"A").End(xlUp).Row)
 
'Data:
Set rExcHdr = rIncHdr.Resize(rIncHdr.Rows.Count-1).Offset(1,0)
 
'Then when you want to copy the visible data to another sheet for eg, use On Error Resume Next so you don't get a debug error.  I use another range ref to hold the visible data:
 
On Error Resume Next
Set rCopy = rExcHdr.SpecialCells(xlCellTypeVisible)
'turn error reporting back on:
On Error Goto 0
 
'test to see if any rows were copied:
If Not rCopy Is Nothing Then   'if it ain't nothing then it's something ie rows were copied!
  rCopy.Copy
  Sheet2.Range("A2").PasteSpecial xlPasteValues
End If

Hope you find this useful!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,816
Messages
5,638,496
Members
417,029
Latest member
lingx86

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