+ Reply to Thread
Results 1 to 13 of 13

VBA doesn't allow entry to be deleted

  1. #1
    Registered User
    Join Date
    03-18-2024
    Location
    Arkansas
    MS-Off Ver
    2007
    Posts
    7

    VBA doesn't allow entry to be deleted

    I'm attempting to use VBA that converts a month name from a data validation list to the month number value in the cell. It does so but if I attempt to delete the contents of the cell, I get an error code and message that the VBA needs to be debugged. I've tried to modify the code to allow the clearing of contents of the selected cell but nothing I've tried works. Can someone please offer a solution? Here's the code I'm using:

    Private Sub Worksheet_Change(ByVal Target As Range)
    selectedNa = Target.Value
    If Target.Column = 50 Then
    selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("Month"), 2, False)
    If Not IsError(selectedNum) Then
    Target.Value = selectedNum
    End If
    End If
    End Sub

    Thank you in advance.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA doesn't allow entry to be deleted

    Untested, but try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: VBA doesn't allow entry to be deleted

    Further to post #2, maybe you don't need the vlookup?


    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-18-2024
    Location
    Arkansas
    MS-Off Ver
    2007
    Posts
    7

    Re: VBA doesn't allow entry to be deleted

    Thank you, TMS and ByteMarks. I tried the suggested modifications and receive a run-time type mismatch error '13' for both. The VBA is using vlookup referencing the named range "Month" (AZ52:BA64) to provide a data validation list of month names (AZ53:AZ64) and instead enter the month number value (BA53:BA64) in the cell where the data validation dropdown is. I've made sure that data validation is allowing manual entry. If it helps to know, I'm using Excel 2007.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA doesn't allow entry to be deleted

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.

  6. #6
    Registered User
    Join Date
    03-18-2024
    Location
    Arkansas
    MS-Off Ver
    2007
    Posts
    7

    Re: VBA doesn't allow entry to be deleted

    Thank you TMS. I created an example in another workbook and it worked just fine leading to the discovery of what is causing the problem. Now I know specifically what the problem is that I need help to solve whish follows below. I followed your instructions to attach the example workbook file but only show a file code(?) in the body of the post. I also found this on the Go Advanced page:
    You may not post new threads BB code is On
    You may not post replies Smilies are On
    You may not post attachments [IMG] code is Off
    You may not edit your posts HTML code is Off
    Does this refer to me?

    That said, the Type Mismatch error is caused because the data validation dropdowns in which a month is selected are in merged-column cells while the VBA only references column 50 (AX). How can I replace the column reference in the VBA to the specific range, $AX$4:$AY$15, to allow merged AX4/AY4 (etc.) to be deleted together?

    Thank you again.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA doesn't allow entry to be deleted

    You may not post new threads BB code is On
    You may not post replies Smilies are On
    You may not post attachments [IMG] code is Off
    You may not edit your posts HTML code is Off
    Does this refer to me?
    I wouldn't worry about that. I think everyone sees that, at least, I do so I assume that they do.

    When you click Go Advanced, you should see your text and, below that, some coloured buttons/icons. And, after that, the option to Manage Attachments. If you click on that, you should have options to select a file. From there, choose a file, upload the file, close the window, and finally submit your post. Good luck.

    If that doesn't work, PM a moderator or administrator.

  8. #8
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: VBA doesn't allow entry to be deleted

    I think everyone sees that, at least, I do so I assume that they do.
    For the record, it's the same for me.

    I remain unconvinced that you need the vlookup to get the month number.

  9. #9
    Registered User
    Join Date
    03-18-2024
    Location
    Arkansas
    MS-Off Ver
    2007
    Posts
    7

    Re: VBA doesn't allow entry to be deleted

    Month to Number example.xlsm

    Thank you again, TMS. I hope the attachment worked. If so:

    As you will see in the example, I've set up data validation in merged cells as they are in my original file. My VBA references only column E. How can I modify the code instead to reference the range E2:F13 and will that allow the substitution of the month number for the name and also then permit entries from the data validation to be deleted?

  10. #10
    Registered User
    Join Date
    03-18-2024
    Location
    Arkansas
    MS-Off Ver
    2007
    Posts
    7

    Re: VBA doesn't allow entry to be deleted

    I'm grateful for your input, ByteMarks. If I don't use vlookup, is there a good alternative to select the month name from the data validation dropdown but enter the month's corresponding number instead in the cell?

    An example of the problem is now included in my previous post.

  11. #11
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: VBA doesn't allow entry to be deleted

    The error is because you are using merged cells.
    Post #3 gives an alternative to the vlookup.

    You could try

    Please Login or Register  to view this content.
    Last edited by ByteMarks; 03-25-2024 at 06:36 AM.

  12. #12
    Registered User
    Join Date
    03-18-2024
    Location
    Arkansas
    MS-Off Ver
    2007
    Posts
    7

    Re: VBA doesn't allow entry to be deleted

    Thank you, ByteMarks. Your code works beautifully as an alternative to my original code. Because of the column width formatting of the original file, providing the best user-friendly placement of month selection dropdowns requires merging cells. Is it possible to allow for merged cells in the code or must I find an alternative placement of the dropdowns to avoid merging cells?

  13. #13
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: VBA doesn't allow entry to be deleted

    It should already allow for the merged cells by assessing the top left cell of the target
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Attempting to delete an entry in list box by selecting the item to be deleted
    By joebbb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2022, 07:05 AM
  2. [SOLVED] Formula doesn't work only for one particular entry??? Confused
    By Anuru in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-06-2021, 08:41 AM
  3. Replies: 3
    Last Post: 07-01-2014, 03:41 PM
  4. [SOLVED] Complicated Macro doesn't work properly if lines are deleted
    By BuzzOffSweetheart in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-11-2012, 01:32 PM
  5. Replies: 0
    Last Post: 04-30-2012, 12:59 PM
  6. Replies: 1
    Last Post: 04-27-2012, 02:07 PM
  7. Next entry row doesn't show on protected sheet.
    By leaning in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2011, 12:50 PM

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