Results 1 to 7 of 7

Thread: Delete rows in VBA?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2004
    Location
    U.K
    Posts
    771

    Delete rows in VBA?

    Hi,

    would it be possible to delete all rows in my worksheets where any field in column F has $, i dont want to delete rows where column F contain $ but only rows where the cell only has $.

    hopefully that makes sense?
    Last edited by frankwhite; Apr 24th, 2013 at 08:44 AM. Reason: Edit, I'm using excel 2010.
    Please mark threads as resolved once the problem has been solved.
    I apprecaite all your help/advice given

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2004
    Location
    U.K
    Posts
    771

    Re: Delete rows in VBA?

    The following coding has helped alot but i'm not sure how to have it running across all worksheets?
    Code:
    Sub test()
    With ActiveSheet
        .AutoFilterMode = False
        With Range("f1", Range("f" & Rows.Count).End(xlUp))
            .AutoFilter 1, "*$*"
            On Error Resume Next
            .Offset(1).SpecialCells(12).EntireRow.Delete
        End With
        .AutoFilterMode = False
    End With
    End Sub
    Please mark threads as resolved once the problem has been solved.
    I apprecaite all your help/advice given

  3. #3
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Delete rows in VBA?

    something like:

    Code:
    Sub delRows()
        Dim wb As Workbook
        Dim ws As Worksheet
        Dim i As Integer
        
        Set wb = ActiveWorkbook     'or set to a specific workbook name
        For i = 1 To wb.Sheets.Count
            Set ws = wb.Sheets(i)
            With ws
                'do stuff
            End With
        Next i
    End Sub

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2004
    Location
    U.K
    Posts
    771

    Re: Delete rows in VBA?

    hi

    i have tried the following but it doesnt do anything?

    Code:
       Dim wb As Workbook
        Dim ws As Worksheet
        Dim i As Integer
        
        Set wb = ActiveWorkbook
        For i = 1 To wb.Sheets.Count
            Set ws = wb.Sheets(i)
    .AutoFilterMode = False
        With Range("f1", Range("f" & Rows.Count).End(xlUp))
            .AutoFilter 1, "*$*"
            On Error Resume Next
            .Offset(1).SpecialCells(12).EntireRow.Delete
        End With
        .AutoFilterMode = False
      Next i
    Please mark threads as resolved once the problem has been solved.
    I apprecaite all your help/advice given

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2004
    Location
    U.K
    Posts
    771

    Re: Delete rows in VBA?

    I have the following coding in place

    Code:
        Dim ws As Worksheet 
        For Each ws In ActiveWorkbook.Worksheets 
             'code
        Next ws
    the problem I have is the coding does work and it removes the rows but it only works for the last worksheet and not all worksheets?
    Please mark threads as resolved once the problem has been solved.
    I apprecaite all your help/advice given

  6. #6
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Delete rows in VBA?

    Try this:

    Code:
    Sub delRows()
        Dim wb As Workbook
        Dim ws As Worksheet
        Dim i As Integer
        
        Set wb = ActiveWorkbook     'or set to a specific workbook name
        For i = 1 To wb.Sheets.Count
            Set ws = wb.Sheets(i)
            With ws
                ws.Range("a1").EntireRow.Delete
                MsgBox "deleted row 1 in sheet " & ws.Name
            End With
        Next i
    End Sub
    It should delete the first row in each worksheet of your active workbook.

  7. #7
    New Member
    Join Date
    Apr 2013
    Posts
    6

    Re: Delete rows in VBA?

    i think your problem need change to follow this code:
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    'code
    Next ws

Posting Permissions

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



Click Here to Expand Forum to Full Width