[VBA] If button is clicked with a certain condition and a message box will pop up

SebastianWidjaja

New Member
Joined
Mar 21, 2018
Messages
10
Hey guys,

I just need a small help here, I have a set of code that is 90% ready, it is very simple code. However, the problem is I want to add an "If" statement when the button is pressed and it meets a certain condition, a message box will pop up automatically after the button is pressed. At the moment, I am looking for a code for if button has been clicked with a specific condition.

Code:
[LEFT][COLOR=#333333][FONT=monospace]Sub Copy()

     If [N2] = Empty Then
        [N2] = [D39]
    Else
        Range("P" & Rows.Count).End(xlUp).Offset(1) = [D39]
    End If
    
   If [N8] <> "" And  Then
        MsgBox "Please Press Reset Button", vbCritical, "Error"
    End If
    
End Sub[/FONT][/COLOR][/LEFT]


Above is my code now. What I want is when cell N8 is filled and you pressed the button (in this case I assigned this Copy code to my Copy Button) a message box will pop up. I do not know what to add after "And".

Thanks in advanced!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I need the And because I need to add another condition if the button is clicked and cell N8 is filled then the message box will come up. I just need a function for if the button has been clicked
 
Upvote 0
What is the other condition?
 
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...1224761-automatic-pop-up-warning-message.html

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
If you run the macro from the button, why do you need another condition?
 
Upvote 0
If you run the macro from the button, why do you need another condition?

This macro copies daily data from cell D39 to N2. As the data changes daily, I want to keep the data only for one week then reset it so I want to keep the data from cell N2 to N8. Once cell N8 is filled I have a button that reset delete the input from cell N2 to N8. So, when cell N8 is filled and you do not press the reset button but you click the "Copy" button, a message box will show up as a reminder.
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top