Results 1 to 3 of 3

Thread: Excel macro variable to delete rows

  1. #1
    Join Date
    May 2008
    Posts
    116

    Excel macro variable to delete rows

    Who can help me with a piece of VB code which provides for:

    Removing a row (in excel) in a column where there are empty cells. So I want all rows in a tab of the empty cells in a specific column.

    So in column B, come on, for example, B6 and B35 or empty cells. I would like the corresponding delete rows.

    Who can help me ??

  2. #2
    Join Date
    May 2008
    Posts
    215

    Re: Excel macro variable to delete rows

    Here is a piece of code that does what you want.

    Code:
      Public Sub pfDelRows () 
    
      totalrows = ActiveSheet.UsedRange.Rows.Count 
    
      For Row = 1 To totalrows 
          If Cells (Row, 2). Value = vbEmpty Then 
              Rows (Row). Delete 
          End If 
      Next Row 
    
      End Sub
    The macro assumes that the actions to be carried out on a worksheet that is currently active. The column where the values are empty in this case, column 2, which you can customize to your own liking.

  3. #3
    Join Date
    May 2008
    Posts
    317

    Re: Excel macro variable to delete rows

    Hi,

    Run this in macro :

    Sub DeleteBlankRows1 () 'deletes the entire row within the selection if the ENTIRE row contains no data. 'We use Long in case they have over 32.767 rows selected. Dim i As Long 'We turn off calculation and screen updating to speed up the macro. With Application. Calculation = xlCalculationManual. Screen Updating = False 'We work backwards because we are deleting rows. For i = Selection.Rows.Count To 1 Step -1 If WorksheetFunction.CountA (Selection.Rows (i)) = 0 Then Selection.Rows (i). EntireRow.Delete End If Next i. Calculation = xlCalculationAutomatic. Screen Updating = True End With End Sub

Similar Threads

  1. How delete rows between two inputs numbers on Excel?
    By Hridayeshu in forum Windows Software
    Replies: 1
    Last Post: 04-01-2012, 07:56 PM
  2. Replies: 6
    Last Post: 23-07-2011, 01:05 AM
  3. Excel macro: Cells.Find finding value from a variable?
    By pkpn in forum Software Development
    Replies: 2
    Last Post: 14-05-2011, 03:31 PM
  4. How to delete bottom rows in excel
    By Dhanajay in forum Windows Software
    Replies: 2
    Last Post: 25-06-2009, 12:22 PM
  5. Delete rows in Excel [VB]
    By Janet J in forum Software Development
    Replies: 2
    Last Post: 03-02-2009, 07:31 PM

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
  •  
Page generated in 1,713,879,501.68056 seconds with 17 queries