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 8385965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:47:59+00:00 2026-06-09T17:47:59+00:00

I am continuing my efforts with data pulled from a mainframe. Currently, I am

  • 0

I am continuing my efforts with data pulled from a mainframe. Currently, I am continuing work on sorting data for use in forms and potential data processing and the like. The data is alphanumeric and is similar in form to one of my previous questions related to my continuing data efforts.

One of my current development lines involved increased usability in the form of macro-enabled buttons. One such button involves a macro which is intended to delete all data in one column “A” from A2 to the end of any existing datarows in the sheet.

The code is as follows:

Sub DeleteCriteria_Click()

Dim CriteriaRange As Range

Dim LastCriteriaCell As Long

With Sheets("Criteria")
    LastCriteriaCell = .Range("A" & Sheets("Criteria").Rows.Count).End(xlUp).Row
    Set CriteriaRange = .Range("A2:A" & LastCriteriaCell)
End With

CriteriaRange.Cells.Select

Selection.Delete

End Sub

Curiously, this code ends up shifting my columns over by one each time I activate the button, and ends up deleting my header and subsequent columns with repeated clicks. This behavior resembles that of a normal delete function for a column. Refactoring the range commands CriteriaRange.Cells.Select | Selection.Delete into the forms CriteriaRange.Cells.Delete and CriteriaRange.Delete does not correct this issue.

My intent is to completely delete the entries so that there are no blanks or leftover datasets when new criteria is entered after the entries are deleted. I thus have two questions:

1) What is causing this behavior, i.e. what I am doing incorrectly, here?

2) How do I correct this behavior to utterly delete the cells or functionally perform the equivalent, thereby prevent any references to blank or null cells, while retaining my column?

  • 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-09T17:48:01+00:00Added an answer on June 9, 2026 at 5:48 pm

    Change your code to

    CriteriaRange.Delete Shift:=xlUp
    

    The default is

    CriteriaRange.Delete Shift:=xlToLeft
    

    Because of this your columns are moved.

    Your code can be written as

    Sub DeleteCriteria_Click()
        Dim LastCriteriaCell As Long
    
        With Sheets("Criteria")
            LastCriteriaCell = .Range("A" & .Rows.Count).End(xlUp).Row
    
            '~~> This is required so that your header cells are not touched
            If LastCriteriaCell < 2 Then Exit Sub
    
            .Range("A2:A" & LastCriteriaCell).Delete Shift:=xlUp
        End With
    End Sub
    

    OR

    Sub DeleteCriteria_Click()
        Dim LastCriteriaCell As Long
    
        With Sheets("Criteria")
            LastCriteriaCell = .Range("A" & .Rows.Count).End(xlUp).Row
    
            '~~> This is required so that your header cells are not touched
            If LastCriteriaCell >= 2 Then _
            .Range("A2:A" & LastCriteriaCell).Delete Shift:=xlUp
        End With
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am continuing working with data pulled from a mainframe. The data is largely
Continuing adopting my code to work with IE... I have a hidden div containing
Continuing from this question : When I am trying to do fopen on Windows,
I am facing a continuing problem distinguishing delegation, composition and aggregation from each other,
I am continuing on from a previous question relating to loading instances of plugins
Continuing from: Why will it always be a null value? When I PageStyle.GetInstance().StartItem =
Continuing with the spirit of using the Stack Exchange Data Explorer to learn SQL,
Continuing from this question With each system call, the function constructs a set of
Continuing from my earlier question , how can I combine the month, day, and
Continuing on from these debates: DDD - the rule that Entities can't access Repositories

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.