+ Reply to Thread
Results 1 to 14 of 14

Macros not working...

  1. #1
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Macros not working...

    Also i must be missing somethings obvious with a couple of macros that arent doing anything...

    firstly a date input in first sheet "Chem Log" which with put the date in column K when column J is changed. Not sure if this is being affected by a macro that if Column J had "disposed" input then that row is moved to sheet 2 "Disposed". or can the two be easily merged?

    And i have a similar move macro that is not working in the third sheet "New Chemical" to transfer the newly input chemicals to sheet one "Chem Log" not sure what to base this is on...
    and this may not be possible but it would help a lot if the last "Chem Number" could be put into "Cell A24" as just a number as that is what another macro is using to get the current chem number when adding new chemicals,

    My macro knowledge is still delevolping though still not sure why they just dont work sometimes so if anyone has any help or ideas it would be most apprechiated, thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macros not working...

    "Also i must be missing somethings obvious with a couple of macros that arent doing anything..."
    Yes, you are. You first need to clear these modules from your VBA project. One way would be to change the name of the modules in to something which resemble what these codes do, not module1,2. You can also add comments to each module on what the code does. If a module is blank, as it is the case with many of the modules you have, you need to delete them.
    You have also lots of events driven codes which should be stored in sheet/workbook, not modules, such as private change/activate/open modules.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macros not working...

    Except from module 4, the rest of the modules should be moved over to sheet/worksheet as they are an event-driven codes.
    I have added comments(with green colour) for one each module.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Macros not working...

    thanks, so just to help my understanding what makes it a event drint code then? and what should be a module?

    i have moved things though still not making them work....

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macros not working...

    An event driven code is triggered by events on either sheet, or thisworkbook. That is why they are stored/reside on sheet/worksheet, not on a module.

    For e.g. You may want to have your code( event driven) to do something when you open a book, or if you change a cell/s(Target) to do something. Unlike a module once triggered, an event become auto. For instance, you may want to copy something if you change a cell. If the code is stored on the standard module, it is not auto, you have to run it, but if it is an event code, all done auto.
    I have just done similar a minute ago. Have a look at it.
    The event driven code resides on sheet/workbook, but can be triggered/called from a module as I did in my post.
    A module is nothing more than a container/storage for a code.

  6. #6
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Macros not working...

    okay thanks, does anything need to be done to the code to make it different or just where it is placed?

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macros not working...

    You still have some event driven code on modules 5 and 6. Have you moved them out?

  8. #8
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Macros not working...

    yeah i moved the event driven code out of the modules but still not working...

  9. #9
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Macros not working...

    I have got the date macro sorted so it is just the moving macro, which i dont want to be event driven so still in a module and a button to start the macro....
    and is it possible to get it also so it moves the last cell in column A to A24 but the number part as it has words in it too...


    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macros not working...

    "the last cell in column A to A24 but the number part as it has words in it too..."
    Not sure I understand?
    You do not need to loop through each target cell.
    Try this one

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Macros not working...

    That is not working...something to do with the
    Please Login or Register  to view this content.
    section of it...thats what the debugger says.

    okay...
    well basically the list of new chemicals that wanting to i am trying to transfer to the big list of active chemicals in chem log.
    but when creating new chemicals it uses the number in cell A24 as what is the last "Chem Number" that has been allocated so when the new chemical is created it can look at that and add one.
    the cells in Chem Number are shown as "Chem 8382" though A24 is just the number part.

    so for examples if 10 chemicals that are numbered from Chem 2943 to Chem 2953 then after transfer would like the number 2953 to move to A24

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macros not working...

    Please Login or Register  to view this content.
    says you are looking in column I. So, instead of specifying any cell in column I, we use the entire column.

    You could also use this line

    Please Login or Register  to view this content.
    Have two end ifs statement.

  13. #13
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Macros not working...

    sorry its still not working, coming up with "Run-time error '424': Object Required"

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macros not working...

    It works for me, so I do not know what is the issue. You could try this line, instead of column 9

    Please Login or Register  to view this content.

    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)

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