• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

condtion for run macro

kalpeshpatel

New Member
n worksheet 1 i create a macro for change font color of "C1" cell when i click command button but i use this macro when "A1", "D10", "e15" cell value is enter then run this macro else a massage box shown please enter data in a1,d10,e15 cell

how
 
Hi, kalpeshpatel!


Let me see if I understood:

a) you have a workbook, with a sheet named Sheet1 which has a button (command button or button control) that changes font color of cell C1 when you click on it... without checking any other condition

b) you want to allow performing that change only when user has entered any values in cells A1, D10 and E15, otherwise you want to display an error message box


If so, I think your VBA code should look like this:

[pre]
Code:
Sub X()
If Len(Range("A1").Value) * Len(Range("D10").Value) * Len(Range("E15").Value) = 0 Then
MsgBox "Please enter proper values in cells A1, D10 and E15, prior trying to change C1 font color. Action cancelled", _
vbApplicationModal + vbExclamation + vbOKOnly, "Error message"
Exit Sub
End If
'your actual code from here
'...
'to here
End Sub
[/pre]
If I'm wrong please post detailed information.


Regards!
 
Back
Top