Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9065493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:30:55+00:00 2026-06-16T16:30:55+00:00

I wonder whether someone could possibly help me please. So that I can maintain

  • 0

I wonder whether someone could possibly help me please.

So that I can maintain a given ‘Input Range’ I’m trying to put together a script which removes cell content from user selected row or rows. Then move all rows with data to the top of my spreadsheet if column “A” starting from row 7 is populated.

I’ve put together the code below which removes the cell content from the row, but I can’t work out how to move the ‘Shift Up’ the rows containing data to sit one under another, omitting any blank rows between the data.

Sub DelRow()
    Dim msg

        Sheets("Input").Protect "password", UserInterFaceOnly:=True
        Application.EnableCancelKey = xlDisabled
        Application.EnableEvents = False
        msg = MsgBox("Are you sure you want to delete this row?", vbYesNo)
        If msg = vbNo Then Exit Sub
        With Selection
            Application.Intersect(.Parent.Range("A:R"), .EntireRow).Interior.ColorIndex = xlNone
            Application.Intersect(.Parent.Range("S:AD"), .EntireRow).Interior.ColorIndex = 37
            Application.Intersect(.Parent.Range("AF:AQ"), .EntireRow).Interior.ColorIndex = 42
            Selection.SpecialCells(xlCellTypeConstants).ClearContents
        End With
        Application.EnableEvents = True

End Sub

I’ve put together a ‘Sort’ macro shown below, and although this works with two consecutive rows containing data, it does not work for rows that I have used my ‘Delete’ macro on.

For example, if I populate the first and second row of my ‘Input Range’, the code correctly sorts the spreadsheet using column “B” as the sort criteria. But if I remove the content of the first row, hence creating a blank row, the ‘Sort’ script does not shift up the second row.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.EnableCancelKey = xlDisabled
    With Sheets("Input")
        If .Range("A7").Value = "" Then Exit Sub
        .Range("B7:AS400").Sort Key1:=Range("$B$1"), _
        Order1:=xlAscending, _
        Header:=xlGuess, _
        OrderCustom:=1, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom, _
        DatOption1:=xlSortNormal
    End With
End Sub

I just wondered whether someone could possibly take a look at this please and offer some guidance on how I need to adapt my code so that I can add the sort functionality.

Many thanks and kind regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:30:56+00:00Added an answer on June 16, 2026 at 4:30 pm

    Following more searching on the internet, I found the following article:
    http://www.access-programmers.co.uk/forums/showthread.php?t=178521

    Using this, I’ve amended my ‘Delete Row’ code to the following which works perfectly:

    Sub DelRow()
        Dim msg
    
            Sheets("Input").Protect "handsoff", UserInterFaceOnly:=True
            Application.EnableCancelKey = xlDisabled
            Application.EnableEvents = False
            msg = MsgBox("Are you sure you want to delete this row?", vbYesNo)
            If msg = vbNo Then Exit Sub
            With Selection
                Application.Intersect(.Parent.Range("A:R"), .EntireRow).Interior.ColorIndex = xlNone
                Application.Intersect(.Parent.Range("S:AD"), .EntireRow).Interior.ColorIndex = 37
                Application.Intersect(.Parent.Range("AF:AQ"), .EntireRow).Interior.ColorIndex = 42
                Selection.SpecialCells(xlCellTypeConstants).ClearContents
            End With
           Application.EnableEvents = True
                With Range("A7:AS400" & Cells(Rows.Count, "A").End(xlUp).Row)
                .Sort Key1:=Range("B7"), _
                Order1:=xlAscending, _
                Header:=xlNo, _
                OrderCustom:=1, _
                MatchCase:=False, _
                Orientation:=xlTopToBottom, _
                DataOption1:=xlSortNormal
    End With
    
    End Sub
    

    Thank you very much to all who have been kind enough to offer help.

    Many thanks and a very happy New Year.

    Kind regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder whether someone can help me please. I'm trying to put together a
I wonder whether someone can help me please. I'm trying to put together a
I wonder whether someone could help me please. I'm trying to put together an
I wonder whether someone can help me please. I've put together this page, which
I wonder whether someone can help me please. I've put together the script below
I wonder whether someone can help me please. I've put together the code below
I wonder whether someone can help me please. I've put together this page which
I wonder whether someone could please help me. I'm trying to incorporate an 'filesize'
I wonder whether someone could help me please. I have put together a form
I wonder whether someone could help me please. I'm put together the following form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.