Consulting

Results 1 to 10 of 10

Thread: Deleting positive values in 45,000 row database

  1. #1
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location

    Deleting positive values in 45,000 row database

    Hi,
    I am trying to delete all rows that have a positive values in column "H".
    I have tried the following which did work but now crashes excel:

    Sub pca()
    Dim rng As Range, Cell As Range, del As Range
        Dim rngNew As Range
        Dim rngDelete As Range
        Dim aCell As Range
        Dim lastRow As Long
    Set rng = Intersect(Range("Free_Money"), ActiveSheet.UsedRange)
        For Each Cell In rng
        If (Cell.Value) > 0 _
        Then
        If del Is Nothing Then
        Set del = Cell
        Else: Set del = Union(del, Cell)
        End If
        End If
        Next Cell
        On Error Resume Next
        del.EntireRow.Delete
    End Sub
    Please see attached which has 45,000 rows of data in the original file - reduced for the download, is this size the problem?

    Any help as always is really appreciated.

    I am working with Windows Home Premium version 6.1.7601 SP 1 Build 7601and Excel version 14.0.6123.5001 (32 bit)
    Attached Files Attached Files
    Regards, Peter.

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Please use code tags !! (you have posted here 109 times ??)

    sub M_snb()
      with columns(8)
        .autofilter 1,">0"
        .specialcells(12)=""
        .autofilter
        .specialcells(4).entirerow.delete
      end with
    End Sub

  3. #3
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Hi SNB,
    Yes after 109 postings I still don't fully understand VBA, that's where self learning at 66 years old gets you, but thank you, your plain and easy code works brilliantly, Thank You.
    Regards, Peter.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by pcarmour View Post
    Hi SNB,
    Yes after 109 postings I still don't fully understand VBA, that's where self learning at 66 years old gets you, but thank you, your plain and easy code works brilliantly, Thank You.
    hi.

    just click the # button on the quick reply panel.

    VBA tags will be inserted. paste the code between these tags.

    [ CODE ]
    Your code here[ /CODE ]

    or write here these tags without spaces (before and after the words CODE and /CODE).
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Hi Mancubus,
    Good to hear from you again.
    OK I can see what you all are showing me, I will load correctly next time.
    Regards, Peter.

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    @pcarmour

    Using code tags has very little to do with VBA as @Mancubus clearly pointed out.
    I think most of us are self taught in VBA (but isn't that the essence of learning: you all have to do it yourself, nobody else can learn something for you). So being self taught sounds to me rather tautologically.
    Please do not boast your seniority without knowing somebody else's; wait until I will be your senior....(won't be that long).
    Last edited by snb; 01-13-2014 at 04:20 PM.

  7. #7
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Hi SNB,
    Thank you for your comments.
    Although your code does work it is far slower than my original code was (when it worked) over this number of rows and when other code to sort the data is added it doesn't delete all positive values. Would a variation of my original code work better?
    Regards, Peter.

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    You might introduce application.calculation=xlcalculationmanual & application.screenupdating =False.

  9. #9
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by pcarmour View Post
    Hi Mancubus,Good to hear from you again.OK I can see what you all are showing me, I will load correctly next time.
    thank you pcarmour.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  10. #10
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    OK, thank you for your help, all working well.
    Regards, Peter.

Posting Permissions

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