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

I'm not sure what is wroing with this code, my goal is to clear any text in
Column E that does not match "HO". Any help is appreciated. Thanks

LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "E"), "HO", vbTextCompare) Then
Rows(RowNdx)ActiveCell.ClearContents
End If
Next RowNdx
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Trouble with this code

There isn't an activecell as such since you aren't selecting cells
through this loop.
this code deletes the rows contents if cell isn't = HO


replace with Range("E" & RowNdx).ClearContents for just the cewll in
column E


Sub clearnotHO()
LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "E"), "HO", vbTextCompare) Then
Rows(RowNdx).ClearContents
End If
Next RowNdx
End Sub

somethinglikeant


JOUIOUI wrote:
I'm not sure what is wroing with this code, my goal is to clear any text in
Column E that does not match "HO". Any help is appreciated. Thanks

LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "E"), "HO", vbTextCompare) Then
Rows(RowNdx)ActiveCell.ClearContents
End If
Next RowNdx


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

why not just

For RowNdx = LastRow To 1 Step -1
if ucase(Cells(RowNdx, "E"))< "HO" then cells(rowndx,"e").clearcontents
next
--
Don Guillett
SalesAid Software

"JOUIOUI" wrote in message
...
I'm not sure what is wroing with this code, my goal is to clear any text
in
Column E that does not match "HO". Any help is appreciated. Thanks

LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "E"), "HO", vbTextCompare) Then
Rows(RowNdx)ActiveCell.ClearContents
End If
Next RowNdx



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Trouble with this code

From the number of similar posts you've made, it kind of looks like you're
having trouble with StrComp.

Maybe just checking for equal would be easier to understand/implement.

LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If lcase(Cells(RowNdx, "E").value) = lcase("HO") then
'do nothing, it's HO.
else
cells(rowndx,"E").ClearContents
End If
Next RowNdx


By comparing lcase() with lcase(), it's the same as the vbTextCompare.



JOUIOUI wrote:

I'm not sure what is wroing with this code, my goal is to clear any text in
Column E that does not match "HO". Any help is appreciated. Thanks

LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "E"), "HO", vbTextCompare) Then
Rows(RowNdx)ActiveCell.ClearContents
End If
Next RowNdx


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Trouble with this code

Thanks Dave, yes this was easier...fear not, next week I attend a VBA Class
for 10 days! Yea!

"Dave Peterson" wrote:

From the number of similar posts you've made, it kind of looks like you're
having trouble with StrComp.

Maybe just checking for equal would be easier to understand/implement.

LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If lcase(Cells(RowNdx, "E").value) = lcase("HO") then
'do nothing, it's HO.
else
cells(rowndx,"E").ClearContents
End If
Next RowNdx


By comparing lcase() with lcase(), it's the same as the vbTextCompare.



JOUIOUI wrote:

I'm not sure what is wroing with this code, my goal is to clear any text in
Column E that does not match "HO". Any help is appreciated. Thanks

LastRow = Cells(Rows.Count, "E").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "E"), "HO", vbTextCompare) Then
Rows(RowNdx)ActiveCell.ClearContents
End If
Next RowNdx


--

Dave Peterson



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
Trouble Adding VBA Code to Module; Bug in Excel/VBE? Mat P:son Excel Programming 4 April 20th 06 04:17 PM
Trouble Condensing Code Ikaabod Excel Programming 3 April 11th 06 09:53 PM
If than Else Trouble Goofy Excel Worksheet Functions 2 February 19th 06 10:48 AM
dim trouble jocke Excel Discussion (Misc queries) 7 October 6th 05 08:55 PM
Print dialog code trouble Tim[_36_] Excel Programming 1 April 18th 04 08:46 AM


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