Consulting

Results 1 to 6 of 6

Thread: Solved: how can i change this code to identifiy the 2 digit no?

  1. #1

    Solved: how can i change this code to identifiy the 2 digit no?

    hi
    how can i change this code to identify the 2 digit no

    [vba]day1 = "1"
    With ws1
    For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 8 Step -1
    If InStr(1, .Cells(i, 2).Value, day1) = 1 Then
    .Cells(i, 2).EntireRow.Delete

    End If
    Next i

    End With[/vba]
    this code work untill if the cell value is one digit but if it 11,12,13,14,15,16,17,18,19 than also it delete the row how can i change that not to delete those row?

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by rrosa1
    hi
    how can i change this code to identify the 2 digit no...

    this code work untill if the cell value is one digit but if it 11,12,13,14,15,16,17,18,19 than also it delete the row how can i change that not to delete those row?
    This seems confusing. Until/if woulld seem to be opposite, you start by askking to identify 'the 2 digit no', but then say you do not want to delete these rows.

    How about giving us some sample data of what we are likely to encounter in the cells, and which would be deleted and which not?

    Mark

  3. #3
    i have following value in column B
    Days
    1 <- i want to delete this row
    2
    4
    3
    1 <-this row
    5
    2
    6
    1 <-this row
    19
    1 <-and this row

    not the 19 row but it delete 19 row also i hope i am explain that can be understandable
    thanks for help.

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    how about [VBA]With ws1
    For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 8 Step -1
    If Len(.Cells(i, 2).Value) = 1 Then
    If InStr(1, .Cells(i, 2).Value, day1) = 1 Then
    .Cells(i, 2).EntireRow.Delete
    End If
    End If
    Next i
    End With[/VBA]

    David


  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why not just use

    [vba]

    With ws1
    For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 8 Step -1
    If .Cells(i, 2).Value = 1 Then
    .Rows(i).Delete

    End If
    Next i

    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    thanks for help
    Tinbender and XLD
    it work great

Posting Permissions

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