Consulting

Results 1 to 7 of 7

Thread: clear non integers

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    clear non integers

    [vba]Sub deletenonintegers()
    Dim cell As Range
    For Each cell In Selection
    If IsEmpty(ActiveCell) Then Exit Sub
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlUp)).Select
    If cell.numberformat <> " ##" Then
    cell.clear
    End If
    Next
    End Sub[/vba]

    what wrong with it?
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lior03
    [vba]Sub deletenonintegers()
    Dim cell As Range
    For Each cell In Selection
    If IsEmpty(ActiveCell) Then Exit Sub
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlUp)).Select
    If cell.numberformat <> " ##" Then
    cell.clear
    End If
    Next
    End Sub[/vba]
    what wrong with it?
    Yiu use Activecell where you should use cell, and you keep resetting the range

    [VBA]
    Sub deletenonintegers()
    Dim cell As Range
    For Each cell In Selection
    If IsEmpty(cell) Then Exit Sub
    If cell.NumberFormat <> " ##" Then
    cell.Clear
    End If
    Next
    End Sub
    [/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

  3. #3
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi Moshe,

    Could you please edit your posts (click the edit button) and use VBA tags for your code. It only takes a few seconds and makes it far more readable... This is not the 1st time this issue has been brought to your notice.

    Note: If regular posters can't be bothered using VBA tags to make their code readable for the helpers, then I in turn (and I'm sure I'm not the only one) can't be bothered to make any effort to help them with their code.

    Regards,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  4. #4
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Moshe,

    That is an odd way to test for integers. You are not testing for integers at all--you are testing for a particular numberformat.

    The way I usually do it is something like this:

    [VBA] If MyVar = Int(MyVar) Then
    'is an integer
    Else
    'is not an integer
    End If
    [/VBA]

    Of course, even that, I suspect, is not a real test.

  5. #5
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    hello
    i am looking for a method to delete all cell with a
    numberformat such as "00.00%"or "##.00"
    vba.
    [VBA] Sub deletenonintegers()
    Dim cell As Range
    For Each cell In Selection
    If IsEmpty(ActiveCell) Then Exit Sub
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlUp)).Select
    If cell.numberformat = "##.00%" Then
    cell.clear
    End If
    Next
    End Sub
    [/VBA]
    thanks
    moshe

  6. #6
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    I just wanted to quote:
    Quote Originally Posted by johnske
    Hi Moshe,

    Could you please edit your posts (click the edit button) and use VBA tags for your code. It only takes a few seconds and makes it far more readable... This is not the 1st time this issue has been brought to your notice.

    Note: If regular posters can't be bothered using VBA tags to make their code readable for the helpers, then I in turn (and I'm sure I'm not the only one) can't be bothered to make any effort to help them with their code.

    Regards,
    John
    And BTW, I don't understand your logic in your code. Why do you exit the sub on the first empty cell? What if you selection has cells AFTER the first blank cell with the criteria you are looking for?

    And why didn't you use Bob's (xld's) suggestion in your code (in your second post)?




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  7. #7
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    trying to use vba tags

    [VBA]

    Sub deletenonintegers()
    Dim cell As Range
    For Each cell In Selection
    If IsEmpty(ActiveCell) Then Exit Sub
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlUp)).Select
    If cell.numberformat <> " ##" Then
    cell.clear
    End If
    Next
    End Sub


    [/VBA]
    moshe

Posting Permissions

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