+ Reply to Thread
Results 1 to 7 of 7

VB error, "Compile error: value not defined"

  1. #1
    StargateFanFromWork
    Guest

    VB error, "Compile error: value not defined"

    I've used this macro many times before but in this new workbook, I get the
    VB compile error. Here is the code:

    ************************************************************
    Sub DeleteRow()
    ActiveSheet.Unprotect 'place at the beginning of the code
    MyMsgBox = MsgBox("Are you sure you really want to delete this row??
    :oD", vbOKCancel + vbExclamation, "Delete ... ?")

    If MyMsgBox = 1 Then

    Selection.EntireRow.Delete

    End If

    ActiveSheet.Protect ' place at end of code
    End Sub
    ************************************************************

    In another similar case, it was just a question of adding "Option Explicit"
    at the top of the code window. The thing is that this already has that text
    there, so I'm stumped. I searched for this error code, but couldn't figure
    out the resolution to this particular problem.

    Thanks in advance for any help re this. Once this is fixed, I can share the
    workbook. :oD



  2. #2
    Registered User
    Join Date
    06-02-2006
    Posts
    39

    VB error, "Compile error: value not defined"

    Try adding this at the start of the code:

    Dim MyMsgBox as String

  3. #3
    Tom Ogilvy
    Guest

    RE: VB error, "Compile error: value not defined"

    Sub DeleteRow()
    Dim MyMsgBox as Long
    ActiveSheet.Unprotect 'place at the beginning of the code
    MyMsgBox = MsgBox( _
    "Are you sure you really want to delete this row?? :oD", _
    vbOKCancel + vbExclamation, "Delete ... ?")

    If MyMsgBox = 1 Then

    Selection.EntireRow.Delete

    End If

    ActiveSheet.Protect ' place at end of code
    End Sub

    --
    Regards,
    Tom Ogilvy


    "StargateFanFromWork" wrote:

    > I've used this macro many times before but in this new workbook, I get the
    > VB compile error. Here is the code:
    >
    > ************************************************************
    > Sub DeleteRow()
    > ActiveSheet.Unprotect 'place at the beginning of the code
    > MyMsgBox = MsgBox("Are you sure you really want to delete this row??
    > :oD", vbOKCancel + vbExclamation, "Delete ... ?")
    >
    > If MyMsgBox = 1 Then
    >
    > Selection.EntireRow.Delete
    >
    > End If
    >
    > ActiveSheet.Protect ' place at end of code
    > End Sub
    > ************************************************************
    >
    > In another similar case, it was just a question of adding "Option Explicit"
    > at the top of the code window. The thing is that this already has that text
    > there, so I'm stumped. I searched for this error code, but couldn't figure
    > out the resolution to this particular problem.
    >
    > Thanks in advance for any help re this. Once this is fixed, I can share the
    > workbook. :oD
    >
    >
    >


  4. #4
    StargateFanFromWork
    Guest

    Re: VB error, "Compile error: value not defined"

    "kev_06" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Try adding this at the start of the code:
    >
    > Dim MyMsgBox as String


    Thank you! That seems to have done the job perfectly. :oD

    > --
    > kev_06
    > ------------------------------------------------------------------------
    > kev_06's Profile:

    http://www.excelforum.com/member.php...o&userid=35046
    > View this thread: http://www.excelforum.com/showthread...hreadid=549469
    >




  5. #5
    StargateFanFromWork
    Guest

    Re: VB error, "Compile error: value not defined"

    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > Sub DeleteRow()
    > Dim MyMsgBox as Long
    > ActiveSheet.Unprotect 'place at the beginning of the code
    > MyMsgBox = MsgBox( _
    > "Are you sure you really want to delete this row?? :oD", _
    > vbOKCancel + vbExclamation, "Delete ... ?")
    >
    > If MyMsgBox = 1 Then
    >
    > Selection.EntireRow.Delete
    >
    > End If
    >
    > ActiveSheet.Protect ' place at end of code
    > End Sub


    Thanks, Tom!

    Is there a preference to using Dim MyMsgBox as Long over Dim MyMsgBox as
    String? I saw the message with the "String" one first, and used that and it
    seems to work just fine. But wondering if one is better or more appropriate
    than the other??

    Cheers! :oD

    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "StargateFanFromWork" wrote:
    >
    > > I've used this macro many times before but in this new workbook, I get

    the
    > > VB compile error. Here is the code:
    > >
    > > ************************************************************
    > > Sub DeleteRow()
    > > ActiveSheet.Unprotect 'place at the beginning of the code
    > > MyMsgBox = MsgBox("Are you sure you really want to delete this row??
    > > :oD", vbOKCancel + vbExclamation, "Delete ... ?")
    > >
    > > If MyMsgBox = 1 Then
    > >
    > > Selection.EntireRow.Delete
    > >
    > > End If
    > >
    > > ActiveSheet.Protect ' place at end of code
    > > End Sub
    > > ************************************************************
    > >
    > > In another similar case, it was just a question of adding "Option

    Explicit"
    > > at the top of the code window. The thing is that this already has that

    text
    > > there, so I'm stumped. I searched for this error code, but couldn't

    figure
    > > out the resolution to this particular problem.
    > >
    > > Thanks in advance for any help re this. Once this is fixed, I can share

    the
    > > workbook. :oD
    > >
    > >
    > >




  6. #6
    Dave Peterson
    Guest

    Re: VB error, "Compile error: value not defined"

    The msgbox function returns numbers, so Long is better.

    This was taken from xl2003's help:

    Constant Value Description
    vbOK 1 OK
    vbCancel 2 Cancel
    vbAbort 3 Abort
    vbRetry 4 Retry
    vbIgnore 5 Ignore
    vbYes 6 Yes
    vbNo 7 No

    You can use:
    if mymsgbox = 1 then
    But I bet your code will be easier to understand if you use:
    if mymsgbox = vbOk then

    It won't matter to the computer if you use 1 or vbOk, only to a human reading
    the code.


    StargateFanFromWork wrote:
    >
    > "Tom Ogilvy" <[email protected]> wrote in message
    > news:[email protected]...
    > > Sub DeleteRow()
    > > Dim MyMsgBox as Long
    > > ActiveSheet.Unprotect 'place at the beginning of the code
    > > MyMsgBox = MsgBox( _
    > > "Are you sure you really want to delete this row?? :oD", _
    > > vbOKCancel + vbExclamation, "Delete ... ?")
    > >
    > > If MyMsgBox = 1 Then
    > >
    > > Selection.EntireRow.Delete
    > >
    > > End If
    > >
    > > ActiveSheet.Protect ' place at end of code
    > > End Sub

    >
    > Thanks, Tom!
    >
    > Is there a preference to using Dim MyMsgBox as Long over Dim MyMsgBox as
    > String? I saw the message with the "String" one first, and used that and it
    > seems to work just fine. But wondering if one is better or more appropriate
    > than the other??
    >
    > Cheers! :oD
    >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "StargateFanFromWork" wrote:
    > >
    > > > I've used this macro many times before but in this new workbook, I get

    > the
    > > > VB compile error. Here is the code:
    > > >
    > > > ************************************************************
    > > > Sub DeleteRow()
    > > > ActiveSheet.Unprotect 'place at the beginning of the code
    > > > MyMsgBox = MsgBox("Are you sure you really want to delete this row??
    > > > :oD", vbOKCancel + vbExclamation, "Delete ... ?")
    > > >
    > > > If MyMsgBox = 1 Then
    > > >
    > > > Selection.EntireRow.Delete
    > > >
    > > > End If
    > > >
    > > > ActiveSheet.Protect ' place at end of code
    > > > End Sub
    > > > ************************************************************
    > > >
    > > > In another similar case, it was just a question of adding "Option

    > Explicit"
    > > > at the top of the code window. The thing is that this already has that

    > text
    > > > there, so I'm stumped. I searched for this error code, but couldn't

    > figure
    > > > out the resolution to this particular problem.
    > > >
    > > > Thanks in advance for any help re this. Once this is fixed, I can share

    > the
    > > > workbook. :oD
    > > >
    > > >
    > > >


    --

    Dave Peterson

  7. #7
    StargateFanFromWork
    Guest

    Re: VB error, "Compile error: value not defined"

    Thank you! I changed the code and it seems to do the same job but, you're
    right, easier for user. I never knew re the "1" vs. "vbOK" so it's much
    better to use the latter.
    ************************************************************
    Sub DeleteRow()
    ActiveSheet.Unprotect 'place at the beginning of the code
    Dim MyMsgBox As Long
    MyMsgBox = MsgBox("Are you sure you really want to delete this/these
    row(s)?? :oD", vbOKCancel + vbExclamation, "Delete ... ?")

    If MyMsgBox = vbOK Then

    Selection.EntireRow.Delete

    End If

    ActiveSheet.Protect ' place at end of code
    End Sub

    ************************************************************
    This works now, thanks!

    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    > The msgbox function returns numbers, so Long is better.
    >
    > This was taken from xl2003's help:
    >
    > Constant Value Description
    > vbOK 1 OK
    > vbCancel 2 Cancel
    > vbAbort 3 Abort
    > vbRetry 4 Retry
    > vbIgnore 5 Ignore
    > vbYes 6 Yes
    > vbNo 7 No
    >
    > You can use:
    > if mymsgbox = 1 then
    > But I bet your code will be easier to understand if you use:
    > if mymsgbox = vbOk then
    >
    > It won't matter to the computer if you use 1 or vbOk, only to a human

    reading
    > the code.
    >
    >
    > StargateFanFromWork wrote:
    > >
    > > "Tom Ogilvy" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Sub DeleteRow()
    > > > Dim MyMsgBox as Long
    > > > ActiveSheet.Unprotect 'place at the beginning of the code
    > > > MyMsgBox = MsgBox( _
    > > > "Are you sure you really want to delete this row?? :oD", _
    > > > vbOKCancel + vbExclamation, "Delete ... ?")
    > > >
    > > > If MyMsgBox = 1 Then
    > > >
    > > > Selection.EntireRow.Delete
    > > >
    > > > End If
    > > >
    > > > ActiveSheet.Protect ' place at end of code
    > > > End Sub

    > >
    > > Thanks, Tom!
    > >
    > > Is there a preference to using Dim MyMsgBox as Long over Dim MyMsgBox as
    > > String? I saw the message with the "String" one first, and used that

    and it
    > > seems to work just fine. But wondering if one is better or more

    appropriate
    > > than the other??
    > >
    > > Cheers! :oD
    > >
    > > > --
    > > > Regards,
    > > > Tom Ogilvy
    > > >
    > > >
    > > > "StargateFanFromWork" wrote:
    > > >
    > > > > I've used this macro many times before but in this new workbook, I

    get
    > > the
    > > > > VB compile error. Here is the code:
    > > > >
    > > > > ************************************************************
    > > > > Sub DeleteRow()
    > > > > ActiveSheet.Unprotect 'place at the beginning of the code
    > > > > MyMsgBox = MsgBox("Are you sure you really want to delete this

    row??
    > > > > :oD", vbOKCancel + vbExclamation, "Delete ... ?")
    > > > >
    > > > > If MyMsgBox = 1 Then
    > > > >
    > > > > Selection.EntireRow.Delete
    > > > >
    > > > > End If
    > > > >
    > > > > ActiveSheet.Protect ' place at end of code
    > > > > End Sub
    > > > > ************************************************************
    > > > >
    > > > > In another similar case, it was just a question of adding "Option

    > > Explicit"
    > > > > at the top of the code window. The thing is that this already has

    that
    > > text
    > > > > there, so I'm stumped. I searched for this error code, but couldn't

    > > figure
    > > > > out the resolution to this particular problem.
    > > > >
    > > > > Thanks in advance for any help re this. Once this is fixed, I can

    share
    > > the
    > > > > workbook. :oD
    > > > >
    > > > >
    > > > >

    >
    > --
    >
    > Dave Peterson




+ 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