• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

why does the same code misbehave?

This piece of Event code was created using Excel2007 and OS7.Refer to MasterList! Currently, I am on H6. When I hit the 'Tab' key, I should be able to jump to A7 and begin entering the values till I reach H7, where I again hit the 'Tab' key, jump to A8 and this continues. Depending on the value selected in D:D, a range gets copied from a source to destination sheet.
The code was working in this manner when I tested it in 2011. But when i work on it now, it behaves differently. A part of the code gets fired for no apparent reason. It is shown below.
Code:
If (Target.Count > 1) Or (Intersect(Target, Me.Range("D:D")).Count > 1) Then
  Application.EnableEvents = False
  Application.Undo
  MsgBox "Multiple cell changes are NOT allowed.", vbExclamation
  Application.EnableEvents = True
  Exit Sub
  End If
What am I looking wrong over here? Can someone please suggest me how I overcome this problem. The file is attached and the password to view code is vdesai!

Regards
Vilas Desai
 

Attachments

  • test3.xlsm
    157 KB · Views: 15
Last edited by a moderator:
Hi, Vilas Desai!

As a new user you might want to (I'd say should and must) read this:
http://chandoo.org/forum/forums/new-users-please-start-here.14/

And regarding your issue, I downloaded your file, clicked on cell H6, Tab and gone to A7, Tab... and gone to H7, Tab and gone to A8, and so on... It worked properly as expected, maybe because I'm running 2013 version on Windows 7 OS, so if it's an iOS 7 related issue only I'm afraid you'll have to wait for another Mac user. Good luck.

Regards!
 
Dear Sir,
I am not too sure if the problem gets resolved with 2013, but I am still using Excel2007 and windows OS7 Did you try to go beyond the last existing row? Could you open a new row with the formulas copied from the earlier row to the next row. Please let me know your findings. Thanks.
Regards
Vilas Desai
 
Hi Vilas ,

I did get an error , but not the one you have posted ; thereafter , I continued to insert data , and did not face any further problems. You can see in the uploaded file that many new rows have been added.

Narayan
 

Attachments

  • test3.xlsm
    159 KB · Views: 2
Narayan, may I seek your apologies please, because the one you are working on is missing the a part of the code which was causing the problem. , which is now corrected and resent to you as a separate file. thanks and best regards.
 

Attachments

  • Test4_2.xlsm
    144.9 KB · Views: 5
Hi Vilas ,

See your file now.

I changed the following statement to this ; you can see in your file what it was earlier.

If ((Target.Address = ActiveSheet.ListObjects(1).HeaderRowRange.Offset(ActiveSheet.ListObjects(1).ListRows.Count).Address) And Target.Rows.Count = 1) Then Exit Sub

Narayan
 

Attachments

  • Test4_2.xlsm
    147.9 KB · Views: 3
Looks like it is perfect. Will review it few more times during the day. Great job and i really appreciate your talent. Thanks.
 
Dear Narayan, the one thing that I notice now which id different from the original file, is in the original file if after I delete cell D, I am able to select the entire row and delete it. I am asending you another file to verify my need. However I should not be able to select more than one row. I wish I could perhaps call you to explain the situation more clearly. Is that a possibility? Regards, Vilas Desai
 

Attachments

  • Test4_1.xlsm
    153.6 KB · Views: 3
I am not too sure if the problem gets resolved with 2013, but I am still using Excel2007 and windows OS7 Did you try to go beyond the last existing row? Could you open a new row with the formulas copied from the earlier row to the next row. Please let me know your findings. Thanks.
Hi, Vilas Desai!

With 2013 version under Win 7 x64 I started at cell A4 and pressing Tab key I arrived at H9 cell, then continued pressing and holding it and created a bunch of new rows. Not being able to test in under 2011 version under Mac iOS 7, I think it's more an issue of operative systems than of Excel versions.

A bit aside and speaking by myself and considering Windows as OS, I strongly recommend you to stop at 2010 version and don't even dare to install 2013 version: IMHO it's absolutely awful. And here's why:
http://chandoo.org/forum/threads/ch...iving-in-borrowed-time-by-2013-version.14296/

Regards!
 
Hi Vilas ,

I am getting confused , both with the discussion , and with the files involved. Let me put down everything as I see it :

1. You have uploaded a file in your post here :

http://chandoo.org/forum/threads/why-does-the-same-code-misbehave.15918/#post-96335

You labelled it Test4_2.xlsm

2. I uploaded a modified file here :

http://chandoo.org/forum/threads/why-does-the-same-code-misbehave.15918/#post-96345

I labelled it the same Test4_2.xlsm

3. Now , in your most recent post , you have uploaded a file here :

http://chandoo.org/forum/threads/why-does-the-same-code-misbehave.15918/#post-96409

You have labelled it Test4_1.xlsm

What I am doing is re-uploading all 3 files , after renaming them as follows :

1. Test original.xlsm
2. Test modified.xlsm
3. Test latest.xlsm

Hopefully , there are no other versions.

Can you go through all the 3 re-uploaded files , and mention what problem you are facing with which version ? As far as possible , please do not upload any file other than one of these three.

Narayan
 

Attachments

  • Test original.xlsm
    144.9 KB · Views: 1
  • Test modified.xlsm
    150.2 KB · Views: 1
  • Test latest.xlsm
    153.8 KB · Views: 1
Dear Narayan,

OK, Sorry again for the confusions. Let me try improving myself.
I mentioned your modified version is doing exactly what I needed, but it did not allow me to delete an entire row. The way the code was developed earlier (before my first posting on this forum) was :
One cannot select and operate on multiple rows / multiple coloumns / multiple cells. It throws up error message.
If the user wants to delete an entire row which was earlier edited (and not blank row), then he first needs to 'delete' contents in cell D, right click - select corresponding row number on extreme left of the wsh and then click 'delete' the selected row.
I could achieve this in version "latest" which is the reason why i sent you this file to try it out. It has two rows of data Row 5 and Row 6. Delete D6 and then delete the row 6. It works.
I could not achieve this part of the function in "modified" version.
However tough "latest" version had issues which you resolved in "modified"
Hereon, I will not direct you to "original".

I wish I am successful in giving you the correct picture. Again, sorry for the confusions.

Thanking you with best regards
Vilas Desai
Hi, Vilas Desai!

With 2013 version under Win 7 x64 I started at cell A4 and pressing Tab key I arrived at H9 cell, then continued pressing and holding it and created a bunch of new rows. Not being able to test in under 2011 version under Mac iOS 7, I think it's more an issue of operative systems than of Excel versions.

A bit aside and speaking by myself and considering Windows as OS, I strongly recommend you to stop at 2010 version and don't even dare to install 2013 version: IMHO it's absolutely awful. And here's why:
http://chandoo.org/forum/threads/ch...iving-in-borrowed-time-by-2013-version.14296/

Regards!

Dear SirJB7,

Thank you for your valuable inputs. Please advise if you suggest Excel2010 with Windows OS 7 is the best combination of the latest releases. If an user has Excel2013 may be he would find difficulties in using this application. Is that the case?. Please advise.

Regards, Vilas Desai
 
Hi Vilas ,

See this file. The requirement that you need to delete the contents of the cell in column D before you can delete the entire row is somewhat difficult to understand. I have ignored that.

In this file , you can select the entire row and right click and click on Delete to delete the entire row.

Narayan
 

Attachments

  • Test modified.xlsm
    150.2 KB · Views: 2
Narayan, You have been so much kind and understanding. Thank you for all your efforts. I am good with the present format. I will try to build on this. However, something new that I see now is that the formulas in Col F and Col G are being copied in the next row as should happen with list objects, but these formulas are not getting executed, I had to reach the end of the formula in the formula bar and hit the enter key for the formula to be executed. For sure, you may not have even touched the formula part of the file because that is not a part of the coding, but it is intriguing me as to why would this happen at all? How could changes in the coding affect the formula? Is Excel VBA so much unstable or inconsistent? I am to novice to understand this.
 
Hi Vilas ,

Sorry , but in the process of opening some file from this forum , I don't recollect which one , the recalculation mode got modified to MANUAL.

Please change it to AUTO and save it , and this problem should be resolved.

Narayan
 
No Problems, at all. I did it.
Let me try answering your point quote"The requirement that you need to delete the contents of the cell in column D before you can delete the entire row is somewhat difficult to understand. I have ignored that" unquote.

I have used the process of "Delete Cell D" as a change event. By right click selection of a row, and either deleting the row or clearing the contents of the row does not trigger the change event. The event on Cell D is triggered on two occasions. 1. While entering data in Cell D using drop down list. When I select a data in D, cell E border turns red indicating that the user must make the selection in E before moving forward. When D and E are selected by drop downs, a range is copied from a source to the destination sheet. For every selection in D and E, a range copy from source to destination is effected. The source ranges are found in the sheet "Ranges" where as the destination sheets are those listed in the drop down in cell D. (Alarms, CMD_OP, ControlValve....Gage) Now, let us assume that the user has created 25 rows of data and later realizes that Row 12 was not required meaning that the content in D was not required. So he tries deleting the entire row. But, this deletion does not delete the range which was copied. There could be better ways to achieve this, but I figured out that a change event on cell D was a good option. When Cell D is deleted, the range which was copied gets deleted.

You can notice this by creating 3 rows of same selections in all cells A:E

This is what you would see in the
sheet MasterList
A B D E F
Row 5 --> 2BL-03713M, rev:B Drum level Control Alarms Alarm_Lvl-Hi_Hi 1BL-LAHH101 A
Row 6 --> 2BL-03713M, rev:B Drum level Control Alarms Alarm_Lvl-Hi_Hi 1BL-LAHH101 B
Row 7 --> 2BL-03713M, rev:B Drum level Control Alarms Alarm_Lvl-Hi_Hi 1BL-LAHH101 C

This is what you would see in the sheet Alarms"
Row 5 --> 1BL-LAHH101-A Drum level Control 0 Alarm_Lvl-Hi_Hi
Row 6 --> 1BL-LAHH101-B Drum level Control 0 Alarm_Lvl-Hi_Hi
Row 7 --> 1BL-LAHH101-C Drum level Control 0 Alarm_Lvl-Hi_Hi

When MasterList! D6 is deleted, Alarms! Row 6 is entirely deleted. The file test_modified-1 is attached for your ready reckoning.

This piece of the code was very challenging and I tried it with several experts. It would very harsh on my part if I expect you to know the complexity of the code in such a short time and still be able to solve my problem.

Honestly the code was working the same way as i described above, before I noticed that some thing has gone wrong after I opened it 2 years later. The gentleman who developed this is not traceable. ( 2years gone by!!)

I am not in the biggest hurry to resolve it but would be greatly delighted if I get the help.

Thanks for your patience all this while and with best regards
Vilas Desai
 
Last edited:
Thank you for your valuable inputs. Please advise if you suggest Excel2010 with Windows OS 7 is the best combination of the latest releases. If an user has Excel2013 may be he would find difficulties in using this application. Is that the case?. Please advise.
Hi, Vilas Desai!

First of all I can't talk about Excel running under iOS and Windows differences because I neither use nor have access to Mac. Now from the Windows side, either with Win 7 Ultimate or Win 8.1 Pro -both x64-, I can tell you that I feel more comfortable and less disappointed with Excel version 2010 than with version 2013. In my opinion 2013 version is something that's not worth to even give a try, that has less integrated components (Excel, VBE -Visual Basic Environment/Editor-, help files), that makes it harder -when it should make it easier- to work with and to develop for.

Particularly in your case I don't know if Excel 2010 would be better than 2013 for using this workbook, it'll all depends on the users installed version. What I think is that if it works fine on either versions, I'd choose 2010 without any doubt.

Regards!
 
Hi Vilas ,

Thanks for the explanation ; now I understand why it is necessary to clear the contents of the cell in column D.

However , I am still not able to understand what your problem is ; what is the problem you are facing in the test_modified workbook ? Since you have not uploaded the test_modified-1 workbook , I am not in a position to proceed.

Narayan
 
Dear Narayan, My sincere apologies again that I did not answer your email. Actually I get a notification on my gmail account if some one replies to my postings. But on this occasion I did not get it, and so I missed replying you.
first up, thanks again for your courtesy. From your reply above, quote "now I understand why it is necessary to clear the contents of the cell in column D" unquote, I actually do not want to Clear the contents of cell D, I want the user to be prevented from using this instruction (right click selection of Row and clear content or right selection of cell D and clear content) because the 'clear content' will not trigger the event. Please go through below lines, I have tried to explain in more details how the code is expected to work.

MasterList! has 8 columns A: PID reference, B: Service Area, C: Service Equipment, D: Instrument_Type, E: Instrument, F: Tag_No., G: Suffix, H: RedLvl. All Cols except G and H are Drop Down Lists. G and H are formula based. The event based code belongs to this wsh. Event changes are performed in Cell D. When a data from drop down list is selected in Cell D, Cell E border changes to Red, prompting the user to select the data into Cell E from its own drop down list. Changes in Cell D trigger an event. This proceeds as below:

When entries in Cell D and Cell E are made, a range gets copied from a source sheet to a destination sheet.

The Range, Source Sheet and Destination sheets along with offsets are mentioned in the wsh List!

As the rows in the MasterList! get populated, the appropriate ranges are copied in appropriate sheets along with the tag numbers. The Tag_No gives an exact identification of which range is copied. The Tag_No is unique to every row that is entered in the MasterList! and it is also unique to every copy that is effected in the destination sheets. If the same selections are made for every drop down list in different rows, then the suffixes are added in column G. The ampersand of Tag_No and Suffix is copied as a unique number in the destination wsh.

The application becomes more complex when a certain Row which was entered, is to be deleted. In this situation, the Range which was copied due to the current value of the data in cell D must be the Range which needs to be deleted. The other serious complexity that is involved is just by merely deleting a row or clearing the contents of a row or clearing the contents in Cell D in the MasterList! does not delete the range that was copied in the particular destination. Therefore if the content in cell D is deleted by using the Delete Button on the keyboard, this act of change in Cell D triggers an event that deletes the correct range in the correct destination that was copied due to the current value of the Cell D. It would be perhaps required to avoid using “Clear Contents” by right clicking the particular row, by graying out “Clear Contents” when the row selection is made by using right click. This is only a suggestion and it is not important as to what method is followed to achieve this functionality. The coder may also create Buttons which can do this function.

The user may also just change the current value of cell D (instead of deleting) by selecting a new value. But the effect of this action is same as deleting the current range in a particular destination and inserting a new range in a new destination.

Your file test_modified-1 performs almost exactly as what is described above, except that it allows “Selection of Row by Right Click and using ‘clear contents’ and also allows selection of cell D by right click and clear content.
And therefore when "clear content" is used to clear contents in the row or the Cell D, it does not delete the range which was earlier copied.

continuing with my sincere thanks and with best regards

Vilas Desai
 

Attachments

  • Test modified-1.xlsm
    152.9 KB · Views: 2
Hi Vilas ,

Let me put down my understanding of your requirements , in my own words , especially since the terminology we are using seems to be different.

As far as I know , ClearContents is a VBA method ; we should not be using this terminology , unless we are discussing the VBA application of this method. In my opinion , we are still discussing user interaction on the worksheet , which does not involve any VBA.

1. Data entry is done on the sheet tab named Masterlist.

2. Whenever a valid row of data is entered , it is entered into the appropriate sheet , based on the selection in column D ; this is done by the UpdateValues procedure.

3. Whenever a mistake is detected , and needs to be undone , the procedure to be followed is to be discussed and agreed upon , but my opinion would be that once data has been entered , no in-cell editing or deletion should be allowed ; the entire table row should be locked so that the only option possible should be to click a button which can be provided on the Masterlist sheet itself ; clicking the button would delete either the active row , or prompt the user to select a row to delete. Thus , we can ensure that deleting a row on the Masterlist also deletes the corresponding entry in the respective individual sheet.

Let me go back to your first workbook , which I had reuploaded as Test original.xlsm

Can you say how I can start data entry on a new row ?

Narayan
 
Thanks again Narayan, Please see the attachment. I have tried to explain the procedure to populate the MasterList by addition of rows. I have added 12 rows for your ready reckoning.

In the workbook Test original.xlsm I had the difficulty that I could not enter new rows into MasterList which is where you helped me and came out with the modified project Test modified-1.xlsm


Best regards
Vilas Desai
 

Attachments

  • Test modified-1.xlsm
    160.6 KB · Views: 1
Hi Vilas ,

I tried deleting a row by directly clicking on the row heading to select the entire worksheet row , and after right-clicking , selected Delete from the menu.

If the corresponding cell in column D is not blank , I get the message :

Deleting cells is disabled in the MasterList

If I go to the cell in column D , press the DEL key to clear the cell , and then do the above action , then the entire table row is deleted.

It seems to be working the way you have described it ; what is the problem with this procedure ?

Narayan
 
Hello Narayan,
Your understanding is perfect. The problem is from the user side. Instead of using the 'delete' key he also has the option of selecting the entire row and using the 'clear' option from the list. This is what I dont want the user to try doing. Becuae this will clear the row but it will not achieve this task quote "Thus , we can ensure that deleting a row on the Masterlist also deletes the corresponding entry in the respective individual sheet." unquote. So, in effect I want to block the user any means of deleting a Row in the MasterList, except that he follows this method --> Select Cell D in Master List--> hit 'delete' key from key board --> Select that particular entire row --> select the option 'delete'
I hope to make it sound good this time around.
Best regards
Vilas Desai
 
Hi Vilas ,

OK , I have understood now.

Shall we say that the user should be prevented :

1. from clearing any cell in a row other than a cell in column D

2. from clearing the entire table row i.e. cells from column A through column H

Narayan
 
Thanks again. I would put it this way:
1. The user must be prevented from using any means of Clearing any cell including cell in Col D
2. The user must be prevented from using any means of Clearing any Row in the MasterList.
3. The user must be provided only "delete" Cell D method of deleting an incorrect entry.

If the user tries to Clear cell content or Clear Row or clear any column in the entire worksheet MasterList, this must be prevented with a message "Clearing cell / row / column is not allowed"
 
Back
Top