[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!
 
Surely if N8 has data then the reset button has not been clicked, so there is no need to test for anything other than if N8<>""
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If I olnly have N8 <>" on my if statement, the message box will pop up when I am filling N8. However, what I am looking for is when N8 is filled and I pressed the copy button, the message box will pop up, not when I am filling in cell N8.
 
Last edited:
Upvote 0
Sorry, but I do not understand what you are trying to do.
At the moment you copy code has nothing to do with N8 other than checking if it's blank or not.
 
Upvote 0
that's why I am asking help here because I don't know what to add in the if statement other than if N8 is blank or not. I do not know what code to put if the button has been clicked and N8 is filled then the message box show up. I am new into this macro vba I learnt this myself only less than a few days. I don't know all the codes that I can use. I guess its alright if you cannot help.

Thanks tho!
 
Upvote 0
If N8 is not blank when you click the copy button this will show the message box
Code:
Sub Copy()

     If [N2] = Empty Then
        [N2] = [D39]
    Else
        Range("P" & Rows.Count).End(xlUp).Offset(1) = [D39]
    End If
    
   If [N8] <> "" Then
        MsgBox "Please Press Reset Button", vbCritical, "Error"
    End If
    
End Sub
but I'm not sure that that is what you're after
 
Upvote 0
If N8 is not blank when you click the copy button this will show the message box
Code:
Sub Copy()

     If [N2] = Empty Then
        [N2] = [D39]
    Else
        Range("P" & Rows.Count).End(xlUp).Offset(1) = [D39]
    End If
    
   If [N8] <> "" Then
        MsgBox "Please Press Reset Button", vbCritical, "Error"
    End If
    
End Sub
but I'm not sure that that is what you're after

that is not what I am after, I know I am missing a code in the if statement and I don't know what is it. when N8 is not blank (filled) and I pressed the copy button, the message box will pop up. But I don't know what to add in the if statement
 
Last edited:
Upvote 0
What is in cell D39?

It is a data that changes everyday. So I want to keep the data in a table from N2:N8 and I don't want to keep the data more than N8. I am not the only one who uses the file so I want to set up a reminder for everyone when N8 is not blank (filled) and they press the copy button it shows up the message box without copying the data to cell N9.
 
Last edited:
Upvote 0
But you only copy that to N2 if its empty, otherwise you copy it to col P
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,405
Members
449,157
Latest member
mytux

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