Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default IF NOT between

I curently have this code which works wonderfully, i need to adapt it to
delete a line if the value in column DW in NOT equal to or between the values
in text boxes 5 and 6 (5 always being less than or equal to 6)

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DW"), Cells(Rows.Count, "DW").End(xlUp))

With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i) = UserForm7.TextBox5 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With

All help very much appreciated

Thanks
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default IF NOT between

The If..Then statement looks correct to me (given the description of what
you said you wanted to do). Did you actually try the statement or did you
just look at it and decide it was the same as what you tried earlier? Are
you sure you tried the SAME statement as Nigel posted... with the SAME
comparison operators he shows?

--
Rick (MVP - Excel)


"Miree" wrote in message
...
I have tried this already for some reason it deletes all the rows

"Nigel" wrote:

If .Cells(i) < UserForm7.TextBox5 Or .Cells(i) UserForm7.TextBox6 Then
.Cells(i).EntireRow.Delete
End If


--

Regards,
Nigel




"Miree" wrote in message
...
I curently have this code which works wonderfully, i need to adapt it to
delete a line if the value in column DW in NOT equal to or between the
values
in text boxes 5 and 6 (5 always being less than or equal to 6)

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DW"), Cells(Rows.Count,
"DW").End(xlUp))

With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i) = UserForm7.TextBox5 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With

All help very much appreciated

Thanks




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default IF NOT between

I was sure this was what I did but tested it anyway and it still did not
work. This is the full code I used maybe the problem is somewhere else

Sub FluidVolumeFilter()

If UserForm7.TextBox6 = "" Then
UserForm7.TextBox6 = UserForm7.TextBox5
End If

If UserForm7.TextBox5 = "" Then
UserForm7.TextBox5 = UserForm7.TextBox6
End If


Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DW"), Cells(Rows.Count, "DW").End(xlUp))

'Work backwards from bottom to top when deleting rows

With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i) < UserForm7.TextBox5 Or .Cells(i) UserForm7.TextBox6
Then
.Cells(i).EntireRow.Delete
End If

Next i
End With
End Sub


"Rick Rothstein" wrote:

The If..Then statement looks correct to me (given the description of what
you said you wanted to do). Did you actually try the statement or did you
just look at it and decide it was the same as what you tried earlier? Are
you sure you tried the SAME statement as Nigel posted... with the SAME
comparison operators he shows?

--
Rick (MVP - Excel)


"Miree" wrote in message
...
I have tried this already for some reason it deletes all the rows

"Nigel" wrote:

If .Cells(i) < UserForm7.TextBox5 Or .Cells(i) UserForm7.TextBox6 Then
.Cells(i).EntireRow.Delete
End If


--

Regards,
Nigel




"Miree" wrote in message
...
I curently have this code which works wonderfully, i need to adapt it to
delete a line if the value in column DW in NOT equal to or between the
values
in text boxes 5 and 6 (5 always being less than or equal to 6)

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DW"), Cells(Rows.Count,
"DW").End(xlUp))

With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i) = UserForm7.TextBox5 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With

All help very much appreciated

Thanks






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default IF NOT between

Are you testing strings? Because the values in the cells may have unseen
space at the end, this is also true for the form controls.

I generally remove spaces before any string tests, using the TRIM function.

If trim(.Cells(i)) < Trim(UserForm7.TextBox5) Or trim(.Cells(i))
Trim(UserForm7.TextBox6)

You might want to assign the test values to variables before the logical
test, especially if you intend to use them in later tests, as the code can
get a bit messy. For example

With UserForm7
sTB5 = Trim(.TextBox5)
sTB6 = Trim(.TextBox6)
End With

For i = .Rows.Count To 1 Step -1
sCell = Trim(.cells(i))

If sCell < sTB5 Or sCell sTB6 then


etc.



--

Regards,
Nigel




"Miree" wrote in message
...
I was sure this was what I did but tested it anyway and it still did not
work. This is the full code I used maybe the problem is somewhere else

Sub FluidVolumeFilter()

If UserForm7.TextBox6 = "" Then
UserForm7.TextBox6 = UserForm7.TextBox5
End If

If UserForm7.TextBox5 = "" Then
UserForm7.TextBox5 = UserForm7.TextBox6
End If


Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DW"), Cells(Rows.Count,
"DW").End(xlUp))

'Work backwards from bottom to top when deleting rows

With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i) < UserForm7.TextBox5 Or .Cells(i) UserForm7.TextBox6
Then
.Cells(i).EntireRow.Delete
End If

Next i
End With
End Sub


"Rick Rothstein" wrote:

The If..Then statement looks correct to me (given the description of what
you said you wanted to do). Did you actually try the statement or did you
just look at it and decide it was the same as what you tried earlier? Are
you sure you tried the SAME statement as Nigel posted... with the SAME
comparison operators he shows?

--
Rick (MVP - Excel)


"Miree" wrote in message
...
I have tried this already for some reason it deletes all the rows

"Nigel" wrote:

If .Cells(i) < UserForm7.TextBox5 Or .Cells(i) UserForm7.TextBox6
Then
.Cells(i).EntireRow.Delete
End If


--

Regards,
Nigel




"Miree" wrote in message
...
I curently have this code which works wonderfully, i need to adapt it
to
delete a line if the value in column DW in NOT equal to or between
the
values
in text boxes 5 and 6 (5 always being less than or equal to 6)

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DW"), Cells(Rows.Count,
"DW").End(xlUp))

With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i) = UserForm7.TextBox5 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With

All help very much appreciated

Thanks





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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



All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"