+ Reply to Thread
Results 1 to 3 of 3

Macro to Add Message Based on Cell Value

  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    Jensen Beach, FL
    MS-Off Ver
    Excel 2016
    Posts
    41

    Macro to Add Message Based on Cell Value

    Hi! I need a macro that will go to the first empty column in a spreadsheet, and then name the cell in Row 1 "Full Comment" and then in that column, row 2, look at the amount in column AC (and in some cases compare it to that in AD) and then plug in a message based on that amount. Once it has put the message there, I need it to copy and paste special down the column so that only the value is left in the cell (removing the formula).

    Here is what I used to use (Sub AddGiftMessage_6) which worked fine for a long time. Now however there are more parameters and messages required and I am trying to use the code in the second code section (Sub NewGiftPoss) below (based on a previous post) but I can't make it work plus it isn't doing everything I need it to (copying the formula down, paste special to overwrite the formula, etc.).

    Any help you could give me would be greatly appreciated.

    Thanks in advance!
    Spacle

    P.S. I had to add a space in every "select" because of the Sucuri firewall issue.

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Macro to Add Message Based on Cell Value

    First, the case statement. As soon as a true case statement occurs, it runs the code until it hits the next Case statement and then exits the entire select case block of code. So, since your first case statement is if it is > 1, then that is likely true for most of your line items, so it then says $5 per pay period. Maybe you meant < 1? I also don't see how 'Is < Range("AD2").Value" is supposed to work. For example, what if AD2 is 400 and giftValue is 300? In the statement above, the first, third, and sixth case statements are true. It is not clear which one you would want to work. As it stands, excel will only perform the first one.

    Second, you are using AC2 in your text string. Use giftValue instead since you already have the value of AC2 in that variable. You are also using AD2 out of context, and you need to use "Range("AD2")" to properly reference that cell in a macro.

    Third, TEXT is not a VBA function (it's an excel spreadsheet function). The pseudo-equivalent in VBA is FORMAT.

    Fourth, it is not copying and pasting since you don't have that code in it. In your top code, you have the Selection.Copy and Selection.PasteSpecial commands which are not present in your bottom code.

    Fifth, I would recommend steering away from VBA for this case statement and just use some nested IF statements in your cells. It won't be pretty with all of that text, but it may be simpler. I'd recommend using a cheater column to determine the amount, and then use that result in your message text. Something like (for the amount):
    =if(AC2<1,5,if(AC2<900,AC2*1.1,if(AC2<980,1000,AD2)))
    Note that the above does not handle your 'Is < Range("AD2").Value' statement, since it is not clear how that is supposed to work.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Registered User
    Join Date
    04-23-2013
    Location
    Jensen Beach, FL
    MS-Off Ver
    Excel 2016
    Posts
    41

    Re: Macro to Add Message Based on Cell Value

    Thanks very much for the reply, Pauleyb!

    I am now trying to modify my original code with the nested IFs as you suggested but am still getting an error. Any ideas why it isn't working would be greatly appreciated.

    Thanks!
    Spacle

    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. Message Box based on cell value containing formula
    By Rahul15292000 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-04-2018, 05:14 PM
  2. Run a message box / macros based on cell value.
    By npsnps in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-10-2017, 11:25 AM
  3. [SOLVED] auto Populate message on cell B based on input on cell A
    By dineshsachidananda in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2014, 03:26 PM
  4. Macro that will hide/unhide rows based on message box answer
    By Aplampert in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2014, 05:50 PM
  5. [SOLVED] how to pop up a message based on a cell value??
    By paul in forum Excel General
    Replies: 6
    Last Post: 02-27-2014, 03:41 AM
  6. [SOLVED] Macro to Create Message box based on cell values
    By aneshdas in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 12-20-2013, 05:24 PM
  7. Macro message box based on cell content
    By ln2012 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-25-2013, 11:51 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