Consulting

Results 1 to 5 of 5

Thread: Modify code to also remove cell borders

  1. #1

    Modify code to also remove cell borders

    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.
    [vba]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[/vba]
    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you delete the row, surely the borders go too?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I would like to see a workbook that shows that.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    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?
    or both?

    Rolly

Posting Permissions

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