+ Reply to Thread
Results 1 to 4 of 4

If Then Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    09-08-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    20

    If Then Macro

    Special thanks to tigeravatar on helping me with my last Macro. After my initial post, I figured out the what was wrong with my last macro.

    With regards to this current project, I am trying write a simple if else statement that is trying to state that if cell "I19" is selected the message "enter number of property address" is display and If cell "I15" is selected then the message "enter total commitment amount" pops up. I am just not remembering what statement I need to make it work. Currently I know that this macro applies to every other cell.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        If Intersect(Target, Range("I19")) Is Nothing Then
        MsgBox "Cell " & Target.Address & " is selected" & vbCrLf & _
        "Enter Total Commitment Amount", vbExclamation + vbOKOnly, "ATTENTION"
        Else
        MsgBox "Cell " & Target.Address & " is selected" & vbCrLf & _
        "Enter number of Property Address", vbExclamation + vbOKOnly
        
        End If
    
    End Sub
    Last edited by Armored Wing; 12-15-2011 at 01:24 PM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: If Then Macro

    Hi,

    try this

    Sub worksheet_selectionChange(ByVal target As Range)
    
    If target.Address = "$I$19" Then MsgBox "Cell " & Target.Address & " is selected" & vbCrLf & _
        "Enter Total Commitment Amount", vbExclamation + vbOKOnly, "ATTENTION"
    If target.Address = "$I$14" Then MsgBox "Cell " & Target.Address & " is selected" & vbCrLf & _
        "Enter number of Property Address", vbExclamation + vbOKOnly
    
    End Sub
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    09-08-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: If Then Macro

    Thank you for your help Steffen, I actually discovered my own error just now. I saw that my intersecting ranges was hitting other cells and not the one I specify so I just modify it to "If not intersect" and it worked. I did past your code in excel and it also worked. Once again thank very much for helping me out. Mods can lock this thread now.

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: If Then Macro

    You can close the thread by marking your thread os solved.
    You can se how in the forum rules, theres a link right below my post

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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