Do not use on any
shared computer
August 29, 2008 10:48pm pdt
 
[x]
Attachment Details

Need VBA script to auto-insert value upon row insert

Tags: Microsoft, Excel, 2003
I have a spreadsheet that is tracking ownerships of land parcels for importing into a database.

Currently it has about 300+ records (rows).  In column A, there is a field named Sort_Key.  They are only whole numbers.  The column is formatted as GENERAL, which when using a whole number, would connote a INTEGER format, right?

Anyway, the whole idea behind the sort key concept is to allow me a way to revert back to the sequence that the data was originally entered, in case I changed the way the spreadsheet was sorted.

I have been told that I will no longer be doing the data input on this spreadsheet, and because of that, will be forwarding the task of data input to a much a very inexperienced Excel user. This person will undoubtedly forget to add the sort key value whenever he adds/inserts a new row, I fear.

To avert this potential catastrophe,  the only thing that I can think of is a VBA script that will automatically insert a new Sort_Key value that is +1 (incremented) from the highest previous value.

------------------------------------------------------------------
The work flow for understanding the construction of the VBA script is as follows:

1 - User initializes INSERT ROW command.

2a - With Excel listening in the background for any INSERT ROW command, the VBA script initializes.

2b - A dialog box will pop up informing the user that upon completion of the VBA script, Excel is going to place a NEW, incremented value in the cell (in Col A) on the new row, for the new Sort Key.

2c - The user will would be prompted to select EITHER: "YES - proceed with new Sort Key Value" or "NO - I don't want to generate a new Sort Key at this time".  If the user selects "No ...", then it will return to the cursor position, and the VBA script will abort.

3a - If the user selects "Yes..", then the VBA script will continue.

3b - The script will read in Col A the MAX value, insert it into the variable to be incremented, then increment it by 1.  The output will be inserted in the new empty cell in Col A.

4 - Once this is done, the script will place the cursor in the next column (which is named: Tract No), and the routine will end.

------------------------------------------------------------------
Some other questions/comments:

A) What if the user changes his mind and decides NOT to insert a row, and wishes to UNDO the new Sort Key?  What are the ramifications here, if any?

B) I was also thinking of another way to do this would be to have a custom button that is assigned to the VBA script.  Whenever the user wanted to insert a new row, and then add a new Sort Key value.  Since this could be construed as a "deliberate" action, it would do away steps 1, 2, and 3a.

C) Is there a hidden value that Excel keeps that could be utilized (in some way) to satisfy this application?

I hope that I've explained this sufficiently, but if not, please place your questions and I will respond to them promptly.

Thanks in advance.

Phil
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Software
Question Asked By: pelampe
Solution Provided By: dmang
Participating Experts: 1
Solution Grade: A
Views: 82
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by dmang

Rank: Master

Accepted Solution by dmang:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pelampe
Author Comment by pelampe:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by dmang

Rank: Master

Expert Comment by dmang:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by dmang

Rank: Master

Expert Comment by dmang:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pelampe
Author Comment by pelampe:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by dmang

Rank: Master

Expert Comment by dmang:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pelampe
Author Comment by pelampe:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by dmang

Rank: Master

Assisted Solution by dmang:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pelampe
Author Comment by pelampe:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pelampe
Author Comment by pelampe:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by dmang

Rank: Master

Assisted Solution by dmang:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by pelampe
Author Comment by pelampe:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by dmang

Rank: Master

Expert Comment by dmang:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628