Setting Variable Range for use in filter

Clayton Michael

New Member
Joined
Dec 7, 2011
Messages
6
Hi All,
I'm very new to VBA and I'm trying to teach myself, but I've hit a wall.
Here's what I'm trying to do:

1. I'm trying to Copy a set of data from one workbook (working ok)
2. Paste that data to a different worksheet that already has other data starting with the first blank row (also working fine)
3. And finally I want the macro to filter what I just pasted for any rows where column K is equal to "0.00" then delete those rows (Problem)

My problem is with the following line:

Sheets("IMPORT DATA").Range("MyRange").AutoFilter Field:=9, Criteria1:="0.000"

I can't figure out how to name a variable range and get it to work with the AutoFilter.

If anyone can help with this or maybe suggest an easier way to do this I'd really appreciate it.

Here's the entire script I'm working with for reference:

Sub EasyInputData()
Dim MyRange As Range
'
' EasyInputData Macro
'

'
Range("A126").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("IMPORT DATA").Select
RowCount = Application.WorksheetFunction.CountA(Range("A:A"))
Range("A1").Offset(RowCount, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.AutoFilterMode = False
Range("A1").Offset(RowCount, 0).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set MyRange = Selection
Sheets("IMPORT DATA").Range("MyRange").AutoFilter Field:=9, Criteria1:="0.000"
Range("A1").Offset(RowCount + 1, 0).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

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