+ Reply to Thread
Results 1 to 15 of 15

Writing a Macro to check cell population & then run another macro.

  1. #1
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Writing a Macro to check cell population & then run another macro.

    Hello all, very new to VBA here, and I've been working on this problem for a few weeks now. Basically, what I'm dealing with is an inventory system. When a cell value reaches below a certain quantity, we have a cell light up with the word "YES" (under the "re-order" column). What I'd like to do is have a macro that checks to see if that cell is populated with "YES" and if it is, to run another macro (which I already have written) that sends out an email notifying us of the need to re-order.

    How it would work: The person pulling out the inventory would fill out this form and click "Submit"

    submitbutton.jpg

    I would then have a "call" code tied to the "Submit" button that when clicked, would run the macro to check cell population and send out the email. The email code is already written and works flawlessly on it's own. I just cant seem to figure out how to write a macro that checks for cell value and then runs it (or not) based on that. Thank you in advance for any and all help.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Writing a Macro to check cell population & then run another macro.

    Maybe:

    Please Login or Register  to view this content.
    Assumes the re-order column is A.

  3. #3
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Writing a Macro to check cell population & then run another macro.

    Hi John, thanks for the response.

    When I place that script into the correct sheet, and try to call on it using the "Call" command when the "Submit" button is pressed, ie.

    "Private Sub cmdSubmit_Click()

    Call Worksheet_Change"

    It gives me an error "Function or Sub not defined". I am guessing Excel is not recognizing this as a macro, since it isn't on my pull down list of Macro's for this project.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Writing a Macro to check cell population & then run another macro.

    No you can't call an event code. I meant for it too be the other way around. Can you post the code that you have?

  5. #5
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Writing a Macro to check cell population & then run another macro.

    What part of the code would you like?

    The project is 4 sheets, with multiple user forms. Really the portion I'm concerned with though is just ONE column of data and generating a macro to check that when a "submit" button is clicked and e-mail if necessary.

  6. #6
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Writing a Macro to check cell population & then run another macro.

    Ok, this is my best shot.

    This is the user form the user will fill out to pull product from the shelves.

    \1

    I then have a separate worksheet which the user never interacts with that lights up quantities drop below a given value.

    \1

    In that sheet, I placed the code you gave me, not knowing it wouldn't work of course.

    \1

    So if I had code that worked, I'd use this command to call on that code, which in turn calls the email macro.

    \1

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Writing a Macro to check cell population & then run another macro.

    I'm sorry I completely misread your thread. The call command would go in your Submit code then.

    Please Login or Register  to view this content.
    I need to see how your Sub is written for a better interpretation. I'm not sure of how you want too activate the Click Event code. Do you want to push the button and it sends out emails for every "Yes" in Column E? Or are you after something else.

  8. #8
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Writing a Macro to check cell population & then run another macro.

    If I can just get it working for just one cell in the column, that's a good enough start to get on everything else.

    I have uploaded a streamlined version of the project. There's a cell in sheet 1 with the word "YES" in it. I also created a button that simply runs the email script. Instead of that button running the email script though, I need a script to check that that cell does in fact have a value of "YES" and THEN runs the email script.

    https://www.dropbox.com/s/gcs78a2rbv...MacroTest.xlsm

    You should be able to "right click save as...." the above file.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Writing a Macro to check cell population & then run another macro.

    I have to go to a meeting now and I'll be able to help you tomorrow, if no one else does:

    Please Login or Register  to view this content.
    This refers to A1 replace it with the range in your sample and test it. Let me know how it goes.

  10. #10
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Writing a Macro to check cell population & then run another macro.

    Awesome! This worked perfectly. Well, sort of.

    What I did was create another button labeled "Check Stock", and used that code. This worked.

    What I couldn't figure out was how to use the same code in conjunction with the "Submit" button on the userform. This is because I don't know the code to refer to that cell from a form.

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Writing a Macro to check cell population & then run another macro.

    You would have to add the sheet name with the Range.

    example: Sheets("Sheet1").Range("A1").value

  12. #12
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Writing a Macro to check cell population & then run another macro.

    So, it would be

    Private Sub cmdSubmit_Click()
    If Sheets("Stock").Range("D2").Value = "YES" Then
    Call CDO_Mail_Small_TextSK2
    End If
    End Sub


    ?

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Writing a Macro to check cell population & then run another macro.

    Do you want the macro to Run on Sheets("Stock") ?

  14. #14
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Writing a Macro to check cell population & then run another macro.

    The macro is just sending out an email, totally in the background, sort of unbeknownst to the user, it doesn't really run ON a sheet, per say.

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Writing a Macro to check cell population & then run another macro.

    Then yes post 12 should do it.

+ 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] Adjust a macro to check for content of a cell and then run a macro on target sheet
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2013, 04:37 AM
  2. Cell population based on meeting condition of another cell using macro.
    By Brungart in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-04-2013, 12:29 PM
  3. Writing a Macro to check cells
    By hockeyadc in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-03-2012, 09:54 AM
  4. Cell Automated population using macro or excel formula
    By rsjamal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-26-2012, 03:24 PM
  5. Problem with check writing macro
    By Mister P in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2011, 11:20 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