+ Reply to Thread
Results 1 to 11 of 11

Help Needed for this Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Help Needed for this Macro

    I have worked this below macro and was succesful in one out come but the others are not working

    1 Delete 2861 from store
    2 Delete DXJ8934\MXA8484\RCF959 from Processor
    3 Delete + values(amt) in PLUS (cardtype)

    The below code works for Delete 2861 from store.The other two need to be in the same shee and start working once option 1 finishes then option 2 should kick in then option 3.Can any one help
    Sub Loop_Delete_Macro()
    
    Dim Counter As Integer
    Dim Todelete As String
    Dim NoIterations As Integer
    
    'DEFINE VALUE TO DELETE
    Todelete = 2861
    
    'DEFINE NUMBER OF ITERATIONS (IE HOW MANY ROWS YOU HAVE IN TOTAL)
    NoIterations = 15000
    
    Counter = 0
    
    Do While Counter < NoIterations
    
    If ActiveCell.Value = Todelete Then
    
    Selection.EntireRow.Delete
    
    Else: ActiveCell.Offset(1, 0).Activate
    
    End If
    Counter = Counter + 1
    
    Loop
    
    End Sub
    https://hotfile.com/dl/224531363/f32ec0c/123.xlsm.html

    This is the sample data I have added the comments on it as well.Can any one help
    Attached Files Attached Files
    Last edited by arlu1201; 05-27-2013 at 01:12 AM.

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Help Needed for this Macro

    I took the liberty to write you a smaller and somewhat easier to understand code.
    Tried on your sample sheet and worked fine, so try this :

    Sub Loop_Delete_Macro()
    lr = ActiveSheet.UsedRange.Rows.Count
    For i = lr To 1 Step -1
    
    'Detect any cells with value 2861 in column E (5) and delete row if found
    If Cells(i, "E").Value = 2861 Then Cells(i, "E").EntireRow.Delete
    
    'Detect any cells with the value DXJ8934 or MXA8484 or RCF959 from column AC (29) and delete row if found
    If Cells(i, "AC").Value = "DXJ8934" Or Cells(i, "AC").Value = "MXA8484" Or Cells(i, "AC").Value = "RCF959" Then Cells(i, "AC").EntireRow.Delete
    
    'Detect any cells with value PLUS in column Y (25) and delete row if found
    If Cells(i, "Y").Value = "PLUS" Then Cells(i, "Y").EntireRow.Delete
    
    Next i
    End Sub
    Please click the * below if this helps

  3. #3
    Registered User
    Join Date
    05-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help Needed for this Macro

    Worked like a charm

  4. #4
    Registered User
    Join Date
    05-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help Needed for this Macro

    Dear JasperD

    With regards to PLUS

    It should delete only Positive values meaning 3000 , 4000 and the remaining negative values -3000 etc should remain . Any thoughts

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Help Needed for this Macro

    Hi Asiva,

    See if this is what you want - If it is then uncomment the penultimate line and delete the last line.

    What will happen is that it will turn all of the entries that would be deleted red

    Sub Asiva(): Dim s As Integer, p As Integer, c As Integer, q As Long, r As Long
    s = Rows("2:2").Find("Store").Column: p = Rows("1:1").Find("Processor").Column
                c = Rows("1:1").Find("Card Type").Column
    r = 1: Do Until WorksheetFunction.CountA(Rows(r)) = 0: r = r + 1: Loop
    For q = 2 To r
    If Cells(q, s) = 2861 Or Cells(q, c) = "PLUS" Or Cells(q, p) = "DXJ8934" Or _
    Cells(q, p) = "MXA8484" Or Cells(q, p) = "RCF959" Then
    'Cells(q, 1).EntireRow.Delete Shift:=xlUp: End If: Next q: End Sub
    Cells(q, 1).EntireRow.Font.ColorIndex = 3: End If: Next q: End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Help Needed for this Macro

    Hi asivaprakash

    sure, change :
    If Cells(i, "Y").Value = "PLUS" Then Cells(i, "Y").EntireRow.Delete
    to this :

    If Cells(i, "Y").Value > 0 Then Cells(i, "Y").EntireRow.Delete
    Please click the * below if this helps

  7. #7
    Registered User
    Join Date
    05-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help Needed for this Macro

    Sure thing that was fast but

    It should delete positive values only when the Code is PLUS

    Meaning If Plus and Greater than 0 delete hope this clarifies sorry for not being specific

  8. #8
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Help Needed for this Macro

    Sorry, misunderstood.
    Change as follows :

    If Cells(i, "Y").Value = "PLUS" And Cells(i, "D").Value > 0 Then Cells(i, "Y").EntireRow.Delete
    Is that what you mean?

  9. #9
    Registered User
    Join Date
    05-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help Needed for this Macro

    Yes sir that's what i wanted

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Help Needed for this Macro

    Asivaprakash,

    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem. Once you have done this please send me a PM and I will remove this request.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    Also,

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE] before your code and [/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Help Needed for this Macro

    asivaprakash,

    Please check the 1st point in post 9.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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