VBA delete blank rows

JoeyGaspard

Board Regular
Joined
Jul 22, 2019
Messages
147
I am trying to use the code below to delete the entire row if the corresponding cell in Column B is empty. It works only if there is nothing in the other columns, such as, if B5 is blank, but G5 is not, it doesnt delete the row? Thanks in advance.

'Delete Blank Rows if No Data in cells in Column B
On Error Resume Next
Sheets("GeneralJournal").Select
Range("B17:B500").Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Range("B17").Select
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Are you saying it delete the entire column, or just clears the B17 downwards?
 
Upvote 0
Have you changed the code at all, because it doesn't do that for me.
 
Upvote 0
Have you changed the code at all, because it doesn't do that for me.
I have not changed anything, other than clicking process bu03, then process bu04, this is what I have:
On Error Resume Next
Sheets("GeneralJournal").Select
With Range("B17:B500")
.Value = .Value
.SpecialCells(xlBlanks).EntireRow.Delete
End With
Range("B17").Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
That's the bit of code I said to change in post#18.
 
Upvote 0
That's the bit of code I said to change in post#18.
It is changed, sorry I sent you the wrong code. I just shared the spreadsheet with you, if you click either of the process buttons, you will see "Main Account" disappear.
 
Upvote 0
Try this
VBA Code:
Sub ProcessPayroll04()

'Remove all accounbt numbers with DUE in the description
Application.ScreenUpdating = False
With Sheets("Import")
        .AutoFilterMode = False
        With .Range("E1", .Range("E" & Rows.Count).End(xlUp))
            .AutoFilter 1, "*Due*"
            On Error Resume Next
            .Offset(1).SpecialCells(12).EntireRow.Delete
            On Error GoTo 0
        End With
        .AutoFilterMode = False
    End With

'Remove all accountnumbers with Net Payroll Payable in the description
'With Sheets("report")
'        .AutoFilterMode = False
'        With .Range("E1", .Range("E" & Rows.Count).End(xlUp))
'            .AutoFilter 1, "*Net Payroll Payable*"
'            On Error Resume Next
'            .Offset(1).SpecialCells(12).EntireRow.Delete
'            On Error GoTo 0
'        End With
'        .AutoFilterMode = False
'    End With


'Clear BU04Data
Sheets("BU04Data").Select
  Range("A1:I150").Select
  Selection.ClearContents
  Range("A1").Select
Sheets("GeneralJournal").Select
  Range("H5").Select
  Selection.ClearContents
  
'Copy Data from Payroll Report to BU04
Dim Ws As Worksheet

Set Ws = Worksheets("BU04Data")
With Worksheets("Import")
   .Range("A1:I1").AutoFilter 1, "4"
      .AutoFilter.Range.Offset(1).Copy Ws.Range("A" & Rows.Count).End(xlUp).Offset(0)
   .AutoFilterMode = False
End With

'Copy BU04 Data to Atlas Upload
With Sheets("GeneralJournal").ListObjects("table1").DataBodyRange
   .Rows("2:" & .Rows.Count).Delete
End With
With Sheets("BU04Data")
   .Range("L1:W" & .Range("A" & Rows.Count).End(xlUp).Row).Copy
End With
Worksheets("GeneralJournal").Range("B17").PasteSpecial Paste:=xlPasteValues

'Clear Clipboard
Application.CutCopyMode = False

'On Error Resume Next
    Sheets("GeneralJournal").Select
    
With Range("Q17:Q" & Cells(Rows.Count, "B").End(xlUp).Row)
  .Formula = "=IF([@AccountType]=""Ledger"",CONCATENATE([@[Main account]],""-"",[@BusinessUnit],""-"",[@Department],""-"",[@CostCenter],""-"",[@CIP],""-""),IF(OR([@AccountType]=""Customer"",[@AccountType]=""Vendor"",[@AccountType]=""Fixedassets""),SUBSTITUTE([@[Main account]],""-"",""\-"",1),[@[Main account]]))"

End With

'Delete Blank Rows if No Data in cells in Column B
'On Error Resume Next
     With Sheets("GeneralJournal").ListObjects("Table1").ListColumns("Main account").DataBodyRange
   .Value = .Value
   On Error Resume Next
   .SpecialCells(xlBlanks).Delete
   On Error GoTo 0
End With
Range("B17").Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top