+ Reply to Thread
Results 1 to 15 of 15

delete specific rows in excel sheet3

Hybrid View

  1. #1
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    delete specific rows in excel sheet3

    In my search I am not sure how long the list will go. Can you please help me with such a circumstance to modify the code?
    
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        Rows("1:1").Select
        Selection.Delete Shift:=xlUp
        ActiveWindow.SmallScroll Down:=40
        Rows("51:51").Select
        Selection.Delete Shift:=xlUp
        ActiveWindow.SmallScroll Down:=48
        Rows("101:101").Select
        Selection.Delete Shift:=xlUp
        ActiveWindow.SmallScroll Down:=44
    End Sub

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: delete specific rows in excel sheet3

    Hi,
    Could you expalin exactly what you want help with as it is not clear?
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: delete specific rows in excel sheet3

    If I am reading it correctly try the code below on a copy of your data
    Sub test()
        Application.ScreenUpdating = False
        Dim i As Long, LstRw As Long, LstCo As Long
        With Sheets("Sheet3")
        LstCo = Cells.Find(What:="*", SearchOrder:=xlColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column + 1
        LstRw = .Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
        .Columns(1).Insert
        With .Range("b1:b" & LstRw)
            With .Columns(1).Offset(, -1)
                For i = 1 To LstRw Step 50
                    .Cells(i, 1).Value = "a"
                Next
            End With
             End With
            With .Range(Cells(1, 1), Cells(LstRw, LstCo))
                .Sort key1:=.Cells(1), order1:=1, Header:=xlNo
            End With
       With .Columns(1)
            .SpecialCells(2, 2).EntireRow.Delete
            .Delete
        End With
        End With
        Application.ScreenUpdating = True
    End Sub
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  4. #4
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: delete specific rows in excel sheet3

    Yes it's the problem WasWodge. You understood it well.

    The above code only deletes the first row (which I want to keep and delete the rest others) but rest others remains same as it is.

    Thanks in advance.

  5. #5
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: delete specific rows in excel sheet3

    Also the next targeted row becomes 50 which I want to delete. and so on as the rows will slip.

  6. #6
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: delete specific rows in excel sheet3

    The above code only deletes the first row
    I am a bit puzzled here. On my data it deletes rows
    1
    51
    101
    151
    201
    251
    301
    351
    401
    451
    501
    et cetera

    The above code only deletes the first row (which I want to keep and delete the rest others)
    Your original post deletes the first row
     Rows("1:1").Select
        Selection.Delete Shift:=xlUp
    Run the code below. What lines have an "a" in column A and which rows do you want to delete (list the first 5 rows to delete from the original data)?
    Sub test()
        'Application.ScreenUpdating = False
        Dim i As Long, LstRw As Long, LstCo As Long
        With Sheets("Sheet3")
        LstCo = Cells.Find(What:="*", SearchOrder:=xlColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column + 1
        LstRw = .Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
        .Columns(1).Insert
        With .Range("b1:b" & LstRw)
            With .Columns(1).Offset(, -1)
                For i = 1 To LstRw Step 50
                    .Cells(i, 1).Value = "a"
                Next
            End With
            End With
            End With
            End Sub
    Last edited by WasWodge; 03-10-2013 at 05:32 PM.

  7. #7
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: delete specific rows in excel sheet3

    Rows with a: 1, 51, 101, 151, 201, 251 and so on.
    I need to delete rows: 52, 103, 154, 205, 256

  8. #8
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: delete specific rows in excel sheet3

    Deleted rushed editing
    Last edited by WasWodge; 03-10-2013 at 05:47 PM.

  9. #9
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: delete specific rows in excel sheet3

    Rows with a: 1, 51, 101, 151, 201, 251 and so on.
    I need to delete rows: 52, 103, 154, 205, 256 and so on.

  10. #10
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: delete specific rows in excel sheet3

    See last post as your last post has registered but not mine

  11. #11
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: delete specific rows in excel sheet3

    The code did not ran.

  12. #12
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: delete specific rows in excel sheet3

    My fault

    Sub test()
        Application.ScreenUpdating = False
        Dim i As Long, LstRw As Long, LstCo As Long
        With Sheets("Sheet3")
        LstCo = Cells.Find(What:="*", SearchOrder:=xlColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column + 1
        LstRw = .Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
        .Columns(1).Insert
        With .Range("b1:b" & LstRw)
            With .Columns(1).Offset(, -1)
                For i = 52 To LstRw Step 51
                    .Cells(i, 1).Value = "a"
                Next
            End With
             End With
            With .Range(Cells(1, 1), Cells(LstRw, LstCo))
                .Sort key1:=.Cells(1), order1:=1, Header:=xlNo
            End With
       With .Columns(1)
            .SpecialCells(2, 2).EntireRow.Delete
            .Delete
        End With
        End With
        Application.ScreenUpdating = True
    End Sub

  13. #13
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: delete specific rows in excel sheet3

    Worked. Thanks a lot.

  14. #14
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: delete specific rows in excel sheet3

    Happy we got there. Remember to mark the thread as solved if you feel your question has been answered.

  15. #15
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: delete specific rows in excel sheet3

    I am really happy too. Marked solved. It wont be possible with out your help.

+ 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