PDA

View Full Version : Modify code to also remove cell borders



rolly
02-17-2011, 09:58 AM
My vba code currently removes all the rows with a value of zero in the "B" column. It works well, but I also need it to remove the cell borders at the same time it removes the rows.
This is so when I print, it will only print the pages with values and not what it does now which is several more pages of blank cells with borders around them.
Sub Remove_rows_zeros_Bcolumn()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

Sheets("Testblocks-to-buy-list").Select
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(4).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the B column in this example
With .Cells(Lrow, "B")
If Not IsError(.Value) Then
If .Value = 0 Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Note: I pulled this code from the web and modified it, but I can't remember where, I'd give credit to them if I knew where I got it.

Thank you for your help,
Rolly

Bob Phillips
02-17-2011, 10:02 AM
If you delete the row, surely the borders go too?

rolly
02-17-2011, 10:36 AM
I wish it worked that way, but I end up with about 170 blank rows with borders around the cells (about 3 pages of wasted paper if printed).

I have another vba sub that sets the print settings for the sheet, but now I still have to manually scroll down and remove the cell borders. I could record a macro, but since the number or rows can change, then a recorded macro would no longer remove the borders on the correct row.

It there a way to remove cell borders on the entire sheet, then add in cell borders ending on the last row of data?

Rolly

Bob Phillips
02-17-2011, 11:03 AM
I would like to see a workbook that shows that.

rolly
02-17-2011, 01:20 PM
I would like to see a workbook that shows that.

Are you asking for someone to post a way to remove cell borders on the entire sheet, then add in cell borders ending on the last row of data or are you asking me to post my workbook?:dunno
or both?

Rolly