+ Reply to Thread
Results 1 to 15 of 15

VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it works!

  1. #1
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it works!

    Hi All,

    I created the following Macro code which is used to clear a form. The code starts off with unprocteting the sheet then checking if a certain cells have images if so it deletes the images followed by doing some other stuff to clear others cells that have information in it.

    Please Login or Register  to view this content.
    The macro seems to work when the form is intially opened and clicked on straight away, but if a cell is selected and then the Macro is used it doesn't like it. A debug message pops up and the following line is highlighted in yellow.:

    Please Login or Register  to view this content.
    As always thank you for all your help. I don't know what I would do without you guys.

    Thanks

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    What is the error message shown when the debug message comes up?

    What module contains this code?

    How is the code invoked?

    The very first line of code selects a cell so it should not matter if a cell is selected before the code runs.

    I can't tell what's wrong from the code, please consider attaching the file with private data removed.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    The message that comes up is Run-time error '1004', Application-defined or object-defined error. (suprisingly the image clears though)

    Module 2 contains the Macro

    Macro is assigned to another image.

    I am just really confused what it might be.

    Thank you for looking into this.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    Which sheet(s) are the unqualified ranges like this meant to refer to?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    Hi Jeff,

    Please find attached file with private data removed (I've sent you the Password via PM)

    Notice image in Cell N38. When you open file and click on "Clear Form" (located AE1) then it works. But when you open file, click on Cell V21, then click on "Clear Form" as error pops up.

    Thanks
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    Quote Originally Posted by Norie View Post
    Which sheet(s) are the unqualified ranges like this meant to refer to?
    Please Login or Register  to view this content.
    The same sheet.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    Every unqualified range reference will refer to the active sheet.

  8. #8
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    So that should be fine right. Did you manage to get a chance to look at the file.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    Quote Originally Posted by f41yaz View Post
    Hi Jeff,

    Please find attached file with private data removed (I've sent you the Password via PM)s
    I do not have a PM from you.

  10. #10
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    pass is "1213"

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    I don't have an answer yet but I have some diagnostics. I can reproduce your error if I select V26 before clicking "Clear Form". If I do not click on anything first, I get this list of shapes in your sheet:

    TextBox 1 $AN$6
    Picture 25 $L$35
    Picture 28 $L$35
    TextBox 2 $K$35
    TextBox 3 $M$41
    AutoShape 52 $I$5
    Picture 22 $AD$2
    Picture 26 $AA$19
    Picture 27 $Y$19
    Picture 50 $M$37
    TextBox 4 $R$38
    Picture 4096 $AH$6
    Picture 4102 $AH$6
    Picture 4104 $AI$6
    Picture 12 $N$38

    However, if I first select V26 then click Clear Form, then I get this shape in addition to the above:

    Drop Down 1

    I am able to reference s.Name but s.TopLeftCell causes an error. I have not heard of data validation dropdown boxes being identified as shapes, and I don't know why it is in the Shapes collection only if you select V26 first.

    So a little data, but I am stuck.

  12. #12
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    Thanks for trying mate. Look at this...

    https://www.mrexcel.com/forum/excel-...rop-downs.html

    https://social.msdn.microsoft.com/Fo...s?forum=isvvba

    it might help?

    Or

    What about a code to delete all shapes except the ones in the sheet currently. Would this solve the problem? by deleting all the additional inserted images i.e. Picture 12 $N$38
    Last edited by f41yaz; 10-19-2018 at 05:49 AM.

  13. #13
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    I seemed to be able to slove it my doing the following:

    Please Login or Register  to view this content.
    Macro 5 =

    Please Login or Register  to view this content.
    Macro 6 =
    Sub Macro6()
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
    If Not shp.Name Like "Drop Down *" And Not shp.Name Like "Comment *" Then
    If Not Application.Intersect(shp.TopLeftCell, Range("AD27:AJ40")) Is Nothing Then
    shp.Delete
    End If
    End If
    Next shp
    End Sub

    Do you guys seen any concerns doing it this way? it seems to work surprisingly.

    Thanks

  14. #14
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,917

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    You don't really need two loops, and if you refer to DrawingObjects rather than Shapes, you don't have to worry about the DV dropdowns:

    Please Login or Register  to view this content.
    Rory

  15. #15
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Debug message pops up if Macro is used after a cell is selected, otherwise it wo

    I will just leave it alone as its working but thanks for this!!

+ 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. [SOLVED] MAcro works OK in Step into debug mode but not doing job when run from command button
    By caabdul in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2018, 10:16 AM
  2. FindNext works when called from macro in debug but not from a cell formula
    By bambi42 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2016, 09:13 AM
  3. [SOLVED] Macro skipping If statements when run but works in debug
    By peage1475 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-13-2013, 01:20 AM
  4. Replies: 11
    Last Post: 08-31-2010, 01:30 PM
  5. Macro Works but not in Debug Step mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2006, 12:35 PM
  6. [SOLVED] Macro sends Excel file by Outlook - works in debug - not realtime
    By DJL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-08-2005, 10:25 AM

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