+ Reply to Thread
Results 1 to 5 of 5

Trouble with this code

  1. #1
    JOUIOUI
    Guest

    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. #2
    somethinglikeant
    Guest

    Re: 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. #3
    Don Guillett
    Guest

    Re: 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
    [email protected]
    "JOUIOUI" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #4
    Dave Peterson
    Guest

    Re: 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. #5
    SITCFanTN
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1