Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Help with code

With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Help with code

Whoops, happened to call my Subject Help with code ALSO!!!

"JMay" wrote in message
:

With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Help with code

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Help with code

Don Thanks, But.... This is Strange *&^*&%$
Your suggested code also Deleted All my rows.

Your code below WITH ALTERATIONS - noted with comments

Sub DGfoo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1) ' t is text
If IsNumeric(t) Then MsgBox t & " is text" 'proof that t is text
If t < "1" Or t < "2" Then 'enter 1 and 2 as text (using quotes)
Rows(i).Delete
End If
Next
End Sub


CONFUSED, Can you see why?

Jim
"Don Guillett" wrote:

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Help with code

Sorry - Forget My Last Send - This is what I meant to send you

Sub DGfoo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1) ' t is numeric
If IsNumeric(t) Then MsgBox t & " is numeric" 'proof that t is numeric
If t < 1 Or t < 2 Then 'enter 1 and 2 as numeric
Rows(i).Delete
End If
Next
End Sub

"Don Guillett" wrote:

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Help with code

Let's try again,,, Here is what I meant to send you - Scratch the other..

Sub DGfoo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1) ' t is numeric
If IsNumeric(t) Then MsgBox t & " is numeric" 'proof that t is numeric
If t < 1 Or t < 2 Then 'enter 1 and 2 as numeric
Rows(i).Delete
End If
Next
End Sub

"Don Guillett" wrote:

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub





  #7   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Help with code

try this:

Sub DGfoo()
Dim i As Long, t As Integer
With ActiveSheet
For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 1 Step -1
t = Right(.Cells(i, 1), 1)
If IsNumeric(t) Then
If t < 1 And t < 2 Then .Rows(i).Delete
End If
Next
End With
End Sub

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36


"JMay" wrote in message ...
Let's try again,,, Here is what I meant to send you - Scratch the other..

Sub DGfoo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1) ' t is numeric
If IsNumeric(t) Then MsgBox t & " is numeric" 'proof that t is numeric
If t < 1 Or t < 2 Then 'enter 1 and 2 as numeric
Rows(i).Delete
End If
Next
End Sub

"Don Guillett" wrote:

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Help with code

KL Thanks - Your code worked, although I thought at first
the AND statement was incorrect - I even changed it to OR
before running the first time - But got same (incorrect) results.

Using AND it worked,, hummmmm... dummy here, can you splain
why the AND is required versus the seeming-correct "OR"?

Thanks,

Jim

"KL" wrote:

try this:

Sub DGfoo()
Dim i As Long, t As Integer
With ActiveSheet
For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 1 Step -1
t = Right(.Cells(i, 1), 1)
If IsNumeric(t) Then
If t < 1 And t < 2 Then .Rows(i).Delete
End If
Next
End With
End Sub

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36


"JMay" wrote in message ...
Let's try again,,, Here is what I meant to send you - Scratch the other..

Sub DGfoo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1) ' t is numeric
If IsNumeric(t) Then MsgBox t & " is numeric" 'proof that t is numeric
If t < 1 Or t < 2 Then 'enter 1 and 2 as numeric
Rows(i).Delete
End If
Next
End Sub

"Don Guillett" wrote:

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub






  #9   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Help with code

If t < 1 Or t < 2 Then .Rows(i).Delete
means that the digit is not equal to 1 or not equal to 2 (at least one is True), so:

Ex.1:
1 is equal to 1, but not equal to 2 - the second is True, so delete
Ex.2:
2 is not equal to 1, but equal to 2 - the first is True, so delete
Ex.3:
3 is not equal to 1, and not equal to 2 - both are True, so delete
etc.

If t < 1 And t < 2 Then .Rows(i).Delete
means that the digit is not equal to 1 and not equal to 2 at the same time (both must necessarily be True)

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36


"JMay" wrote in message ...
KL Thanks - Your code worked, although I thought at first
the AND statement was incorrect - I even changed it to OR
before running the first time - But got same (incorrect) results.

Using AND it worked,, hummmmm... dummy here, can you splain
why the AND is required versus the seeming-correct "OR"?

Thanks,

Jim

"KL" wrote:

try this:

Sub DGfoo()
Dim i As Long, t As Integer
With ActiveSheet
For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 1 Step -1
t = Right(.Cells(i, 1), 1)
If IsNumeric(t) Then
If t < 1 And t < 2 Then .Rows(i).Delete
End If
Next
End With
End Sub

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36


"JMay" wrote in message ...
Let's try again,,, Here is what I meant to send you - Scratch the other..

Sub DGfoo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1) ' t is numeric
If IsNumeric(t) Then MsgBox t & " is numeric" 'proof that t is numeric
If t < 1 Or t < 2 Then 'enter 1 and 2 as numeric
Rows(i).Delete
End If
Next
End Sub

"Don Guillett" wrote:

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub






  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Help with code

KL - Thanks, I better understand..now

when testing <1 or <2 = Result
4 T or T = T
3 T or T = T
2 T or F = F
1 F or T = F

I remember now why I did'nt go into programming
30+ years ago - when I was in a class much like this;

I walked out "drunk-as-a-sailor" - from the confusion..
Didn't deal with it then, so must deal with it now. LOL

In my Senior years

Thanks again for your generous examples, only hope I
can remember and recognize the next time I'm involved
with the same type thing...

Jim May

"KL" wrote:

If t < 1 Or t < 2 Then .Rows(i).Delete
means that the digit is not equal to 1 or not equal to 2 (at least one is True), so:

Ex.1:
1 is equal to 1, but not equal to 2 - the second is True, so delete
Ex.2:
2 is not equal to 1, but equal to 2 - the first is True, so delete
Ex.3:
3 is not equal to 1, and not equal to 2 - both are True, so delete
etc.

If t < 1 And t < 2 Then .Rows(i).Delete
means that the digit is not equal to 1 and not equal to 2 at the same time (both must necessarily be True)

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36


"JMay" wrote in message ...
KL Thanks - Your code worked, although I thought at first
the AND statement was incorrect - I even changed it to OR
before running the first time - But got same (incorrect) results.

Using AND it worked,, hummmmm... dummy here, can you splain
why the AND is required versus the seeming-correct "OR"?

Thanks,

Jim

"KL" wrote:

try this:

Sub DGfoo()
Dim i As Long, t As Integer
With ActiveSheet
For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 1 Step -1
t = Right(.Cells(i, 1), 1)
If IsNumeric(t) Then
If t < 1 And t < 2 Then .Rows(i).Delete
End If
Next
End With
End Sub

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36


"JMay" wrote in message ...
Let's try again,,, Here is what I meant to send you - Scratch the other..

Sub DGfoo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1) ' t is numeric
If IsNumeric(t) Then MsgBox t & " is numeric" 'proof that t is numeric
If t < 1 Or t < 2 Then 'enter 1 and 2 as numeric
Rows(i).Delete
End If
Next
End Sub

"Don Guillett" wrote:

Number vs text. Try this

Set rng = ActiveSheet.range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
For i = rng.Rows.Count To 1 Step -1
t = Right(Cells(i, 1), 1)
If t < 1 Or t < 2 Then
Rows(i).Delete
End If
Next

--
Don Guillett
SalesAid Software

"JMay" wrote in message
...
With Sheet1 containing in Cells A1:A11

a1
a2
a3
a4
b1
b2
b3
b4
c1
c2
c3

Why is this code Not deleting
all and only the ?3's and ?4's

Right Now it is deleting ALL/everything !!
Hair-pulling here ...

Sub foo()
Set rng = ActiveSheet.Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row, 1))
lrow = rng.Rows.Count
For i = lrow To 1 Step -1
t = Right(Cells(i, 1).Value, 1)
If t < "1" Or t < "2" Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub









  #11   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Help with code

"JMay" wrote in message ...
KL - Thanks, I better understand..now

when testing <1 or <2 = Result
4 T or T = T
3 T or T = T
2 T or F = F
1 F or T = F


Yep, something like this. Only the equation for your example is "<1 and <2 = Result"

i.e.:

when testing <1 and <2 = Result
4 T and T = T
3 T and T = T
2 T and F = F
1 F and T = F

when testing <1 or <2 = Result
4 T or T = T
3 T or T = T
2 T or F = T
1 F or T = T

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Help with code

thanks again for your clarification

"KL" wrote in message
:

"JMay" wrote in message ...
KL - Thanks, I better understand..now

when testing <1 or <2 = Result
4 T or T = T
3 T or T = T
2 T or F = F
1 F or T = F


Yep, something like this. Only the equation for your example is "<1 and <2 = Result"

i.e.:

when testing <1 and <2 = Result
4 T and T = T
3 T and T = T
2 T and F = F
1 F and T = F

when testing <1 or <2 = Result
4 T or T = T
3 T or T = T
2 T or F = T
1 F or T = T

--
KL
[MVP - Microsoft Excel]
RU: http://www.mvps.ru/Program/Default.aspx
ES: http://mvp.support.microsoft.com/?LN=es-es
EN: http://mvp.support.microsoft.com/?LN=en-us
Profile: https://mvp.support.microsoft.com/pr...A-9E6C73C09A36


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
How to assign same code inside Option button code space ?? furbiuzzu Excel Programming 1 November 21st 06 02:36 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM


All times are GMT +1. The time now is 10:18 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"