input value for procesing - HELP! Please!

miguel65

New Member
Joined
Aug 6, 2009
Messages
35
Code:

Sub Delete_Rows()
Dim vFirstValue As Long
Dim vSecondValue As Long
Dim V1 As Long
Dim V2 As Long


Dim rng As Range

Set rng = Range("H5", Range("H" & Rows.Count).End(xlUp))

Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False

vFirstValue = Application.InputBox(Prompt:="Enter Value 1", Type:=1)
vSecondValue = Application.InputBox(Prompt:="Enter Value 2", Type:=1)

Columns("H").AutoFilter Field:=1, Criteria1:="<V1=vFirstValue", Operator:=xlOr, Criteria2:=">V2=vSecondValue"

On Error Resume Next
rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0

ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Is there a question to go with this code, or is everyone supposed to guess what is required?
 
Upvote 0
Code:

Sub Delete_Rows()
Dim vFirstValue As Long
Dim vSecondValue As Long
Dim V1 As Long
Dim V2 As Long


Dim rng As Range

Set rng = Range("H5", Range("H" & Rows.Count).End(xlUp))

Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False

vFirstValue = Application.InputBox(Prompt:="Enter Value 1", Type:=1)
vSecondValue = Application.InputBox(Prompt:="Enter Value 2", Type:=1)

Columns("H").AutoFilter Field:=1, Criteria1:="<v1=vfirstvalue", operator:="xlOr," criteria2:=">V2=vSecondValue"

On Error Resume Next
rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0

ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True

End Sub

Hi guys,
I got this code that I worked on previously, it works fine if I do keep changing the values for criteria1 and criteria2 manually. But I am tired of changing them this way. So I thought as soon as I start running the VBA code I get prompted to give Value1 and Value2. The VBA does not crash but it does not do anything.
Thecode is meant to delete any entire row that does not have the expected value within the lowest (criteia1) and the highest value (criteria2).
"H" is the column where the analysed value will decide if the row gets deleted or not.

</v1=vfirstvalue",>
 
Upvote 0
Your code was not in code tags, so I suspect that some of it is missing ... the most important bit actually ... the bit that specifies the criteria for the filter?
 
Upvote 0
Your code was not in code tags, so I suspect that some of it is missing ... the most important bit actually ... the bit that specifies the criteria for the filter?


Code:
Sub Delete_Rows()
    Dim vFirstValue As Long
    Dim vSecondValue As Long
    Dim V1 As Long
    Dim V2 As Long
    
    
    Dim rng As Range
    
    Set rng = Range("H5", Range("H" & Rows.Count).End(xlUp))

    Application.ScreenUpdating = False
    ActiveSheet.AutoFilterMode = False
    
    vFirstValue = Application.InputBox(Prompt:="Enter Value 1", Type:=1)
    vSecondValue = Application.InputBox(Prompt:="Enter Value 2", Type:=1)
    
    Columns("H").AutoFilter Field:=1, Criteria1:="<V1=vFirstValue", Operator:=xlOr, Criteria2:=">V2=vSecondValue"
    
    On Error Resume Next
    rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
    On Error GoTo 0
    
    ActiveSheet.AutoFilterMode = False
    Application.ScreenUpdating = True
     
End Sub
 
Upvote 0
Code:
Sub Delete_Rows()
    Dim vFirstValue As Long
    Dim vSecondValue As Long
    Dim V1 As Long
    Dim V2 As Long
    
    
    Dim rng As Range
    
    Set rng = Range("H5", Range("H" & Rows.Count).End(xlUp))
    Application.ScreenUpdating = False
    ActiveSheet.AutoFilterMode = False
    
    vFirstValue = Application.InputBox(Prompt:="Enter Value 1", Type:=1)
    vSecondValue = Application.InputBox(Prompt:="Enter Value 2", Type:=1)
    
    Columns("H").AutoFilter Field:=1, Criteria1:="<V1=vFirstValue", Operator:=xlOr, Criteria2:=">V2=vSecondValue"
    
    On Error Resume Next
    rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
    On Error GoTo 0
    
    ActiveSheet.AutoFilterMode = False
    Application.ScreenUpdating = True
     
End Sub
 
Upvote 0
Just a guess, but maybe:
Code:
Columns("H").AutoFilter Field:=1, Criteria:=">=" & vFirstValue, Operator:=xlAnd, Criteria2:="<=" & vSecondValue
 
Upvote 0

Forum statistics

Threads
1,224,593
Messages
6,179,791
Members
452,942
Latest member
VijayNewtoExcel

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