Results 1 to 7 of 7

vba macro code error: statement invalide outside type block

Threaded View

  1. #1
    Registered User
    Join Date
    02-17-2012
    Location
    charlotte, nc
    MS-Off Ver
    Excel 2007
    Posts
    25

    vba macro code error: statement invalide outside type block

    I just started working with macros and the vba code. I have read online how to do what I want but when I run the code i get an error "statement invalid outside type block". Here is my code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("C9:C11")) Is Nothing Then
        'Do nothing if more than one cell is changed or content deleted
        If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
                If (C9 = "x" Or c10 = "x" Or c11 = "x") Then
                'display error message
                MsgBox("You can only select 1 yes for this category", vbOKOnly, "Error") As VbMsgBoxResult
                End If              
        
        End If
    End If
    End Sub
    Maybe it has to do with my msgBox it highlights the top line in yellow, but the msgBox is highlighted in blue. Any help would be great! Thanks
    Last edited by satania; 02-20-2012 at 03:42 PM.

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