Results 1 to 1 of 1

Automatically adds number of rows at page break which are deleted due to #REF! error

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Lightbulb Automatically adds number of rows at page break which are deleted due to #REF! error

    Hi,
    ( Please refer to attached file for clear understanding....)
    When the commandbutton1 is used to remove #REF! error, all the rows shift up.
    This affects badly on to the other cells , their purpose size , references etc. I also can not place remaining pages in that sheet on the side of first table due to too many complications.

    I have count function ( green) which counts number of rows having #REF! error.

    I am looking for a VB code which will count number of #REF! rows being deleted ( by press of a command button1) and adds those many rows just below the last row in that page ( as shown in red).

    Is it possible?

    Sheet1 code is as follows
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Column = 5 And Target.Cells.Count = 1 Then
        Target.EntireRow.Copy Destination:=Sheets(2).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
        Target.EntireRow.Delete Shift:=xlUp
        
        End If
    End Sub
    Sheet3 ( command button code is as follows)
    Sub RemoveREFRows()
    Dim delRNG As Range, REFrng As Range, REFfirst As Range
    
    On Error Resume Next
    With Sheets("Sheet3")
        Set REFrng = .Cells.Find(What:="#REF", LookIn:=xlValues, LookAt:=xlPart)
        If Not REFrng Is Nothing Then
            Set REFfirst = REFrng
            Set delRNG = REFrng
            Do
                Set delRNG = Union(delRNG, REFrng)
                Set REFrng = .Cells.FindNext(REFrng)
            Loop While REFrng.Address <> REFfirst.Address
            delRNG.EntireRow.Delete xlShiftUp
            Set REFrng = Nothing
            Set REFfirst = Nothing
        End If
    End With
    
    End Sub
    Any help will be appreciated
    Many thanks
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1