PC Review


Reply
Thread Tools Rate Thread

Change definite value to string reference for criteria

 
 
J.W. Aldridge
Guest
Posts: n/a
 
      13th Oct 2010
Instead of deleting just two criteria in the code ("apples" &
"oranges"), I need it to look at values in string on Sheet "grapes",
Reference A5:A15.

Sub Delete_with_Autofilter_Two_Criteria1()
Dim DeleteValue1 As String
Dim DeleteValue2 As String
Dim rng As Range
Dim calcmode As Long

With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Fill in the two values that you want to delete
DeleteValue1 = "apples"
DeleteValue2 = "oranges"

'Sheet with the data, you can also use Sheets("MySheet")
With ActiveSheet

'Firstly, remove the AutoFilter
.AutoFilterMode = False

'Apply the filter
.Range("H1:H" & .Rows.Count).AutoFilter Field:=1, _
Criteria1:=DeleteValue1, Operator:=xlOr,
Criteria2:=DeleteValue2

With .AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete
End With

'Remove the AutoFilter
.AutoFilterMode = False
End With

With Application
.ScreenUpdating = True
.Calculation = calcmode
End With

End Sub
 
Reply With Quote
 
 
 
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      13th Oct 2010
On Oct 13, 3:14*pm, "J.W. Aldridge" <jeremy.w.aldri...@gmail.com>
wrote:
> Instead of deleting just two criteria in the code ("apples" &
> "oranges"), I need it to look at values in string on Sheet "grapes",
> Reference A5:A15.
>
> Sub Delete_with_Autofilter_Two_Criteria1()
> * * Dim DeleteValue1 As String
> * * Dim DeleteValue2 As String
> * * Dim rng As Range
> * * Dim calcmode As Long
>
> * * With Application
> * * * * calcmode = .Calculation
> * * * * .Calculation = xlCalculationManual
> * * * * .ScreenUpdating = False
> * * End With
>
> * * 'Fill in the two values that you want to delete
> * * DeleteValue1 = "apples"
> * * DeleteValue2 = "oranges"
>
> * * 'Sheet with the data, you can also use Sheets("MySheet")
> * * With ActiveSheet
>
> * * * * 'Firstly, remove the AutoFilter
> * * * * .AutoFilterMode = False
>
> * * * * 'Apply the filter
> * * * * .Range("H1:H" & .Rows.Count).AutoFilter Field:=1, _
> * * * * Criteria1:=DeleteValue1, Operator:=xlOr,
> Criteria2:=DeleteValue2
>
> * * * * With .AutoFilter.Range
> * * * * * * On Error Resume Next
> * * * * * * Set rng = .Offset(1, 0).Resize(.Rows.Count - 1,1) _
> * * * * * * * * * * * .SpecialCells(xlCellTypeVisible)
> * * * * * * On Error GoTo 0
> * * * * * * If Not rng Is Nothing Then rng.EntireRow.Delete
> * * * * End With
>
> * * * * 'Remove the AutoFilter
> * * * * .AutoFilterMode = False
> * * End With
>
> * * With Application
> * * * * .ScreenUpdating = True
> * * * * .Calculation = calcmode
> * * End With
>
> End Sub


Probably just as easy and just as fast to simply use

dim i as long
for i = cells(rows.count,"a").end(xlup).row to 2 step -1
if lcase(cells(i,"a"))="apples" or _
lcase(cells(i,"a"))="oranges" or _
lcase(cells(i,"a"))="grapes" then rows(i).delete
next i
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shortcut to change change cell reference to Absolute reference? =?Utf-8?B?cmljaGs=?= Microsoft Excel Worksheet Functions 12 5th Dec 2009 12:24 AM
Convert cells reference to string reference?? Robert Crandal Microsoft Excel Programming 2 1st Dec 2009 07:46 AM
change change cell reference to Absolute reference art Microsoft Excel Misc 5 13th Mar 2008 02:41 AM
Change a string into a criteria expression wesmorgan7 Microsoft Access Queries 0 19th Jul 2007 10:41 PM
HELP! Change color of a control if criteria meets criteria in an unbound box Aileen Microsoft Access Forms 1 26th Sep 2003 07:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:16 PM.