+ Reply to Thread
Results 1 to 5 of 5

Excel 2003 macro not working in 2010

Hybrid View

davides Excel 2003 macro not working... 05-23-2012, 01:41 PM
wallyeye Re: Excel 2003 macro not... 05-23-2012, 06:50 PM
davides Re: Excel 2003 macro not... 05-24-2012, 06:34 PM
davides Re: Excel 2003 macro not... 05-24-2012, 06:40 PM
wallyeye Re: Excel 2003 macro not... 05-24-2012, 07:04 PM
  1. #1
    Registered User
    Join Date
    05-23-2012
    Location
    Torrance
    MS-Off Ver
    Excel 2010
    Posts
    3

    Excel 2003 macro not working in 2010

    I have the following macro that works on excel 2003 but it doesn't work on 2010. I lower the macro security levels thinking that was the problem but I think it has to be the sintax on 2010 and VBA.
    Thanks in advance fo your help.
    Sub lockmonday()
    '
    ' lockmonday Macro
    
        'Sub Msgbox_Yes_No()
          'Dim Response As Integer
    
          ' Displays a message box with the yes and no options.
          Response = MsgBox(prompt:="Lock Records'Yes' or 'No'.", Buttons:=vbYesNo)
    
          ' If statement to check if the yes button was selected.
          If Response = vbYes Then
             ActiveSheet.Protect UserInterfaceOnly:=True
            Range("E9:E240").Select
        Selection.Locked = True
        Selection.FormulaHidden = False
        
        Range("E9:E240").Select
        Selection.FormatConditions.Delete
        Range("E9:E240").Select
        With Selection.Interior
            .ColorIndex = 43
            .Pattern = xlSolid
        End With
          
           Else
         ' The no button was selected.
             MsgBox "Records Not Locked."
          End If
    
       End Sub
    Last edited by arlu1201; 05-23-2012 at 02:00 PM. Reason: Use code tags in future.

  2. #2
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Excel 2003 macro not working in 2010

    The only thing I could find breaking it was the protection. After moving it to the bottom it worked fine. However, you could shorten and simplify the code a bit:

    Sub lockmonday()
    '
    ' lockmonday Macro
    
        'Sub Msgbox_Yes_No()
          'Dim Response As Integer
    
        ' Displays a message box with the yes and no options.
        Response = MsgBox(prompt:="Lock Records'Yes' or 'No'.", Buttons:=vbYesNo)
    
        ' If statement to check if the yes button was selected.
        If Response = vbYes Then
            With Range("E9:E240")
                .Locked = True
                .FormulaHidden = False
                .FormatConditions.Delete
                With .Interior
                    .ColorIndex = 43
                    .Pattern = xlSolid
                End With
            End With
            ActiveSheet.Protect UserInterfaceOnly:=True
            
        Else
            ' The no button was selected.
            MsgBox "Records Not Locked."
        End If
            
    End Sub

  3. #3
    Registered User
    Join Date
    05-23-2012
    Location
    Torrance
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Excel 2003 macro not working in 2010

    It works great.
    There' one more thing. I have to start with an unprotected sheet otherwise the macros won't work.
    I have the same button for every day of the week, so let's say the condition is "yes" for Monday, the macro executes but it locks the sheet and then the other days of the week won't work, is there a way around this?
    I really appreciate your help!

  4. #4
    Registered User
    Join Date
    05-23-2012
    Location
    Torrance
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Excel 2003 macro not working in 2010

    I would like to add that the active sheet needs to be protected in order to avoid tampering with formulas

  5. #5
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Excel 2003 macro not working in 2010

    So, how do you know which day of the week you want to protect/unprotect?

            ActiveSheet.Unprotect
            With Range("E9:E240")
                .Locked = True
                .FormulaHidden = False
                .FormatConditions.Delete
                With .Interior
                    .ColorIndex = 43
                    .Pattern = xlSolid
                End With
            End With
            With Range("F9:F240")
                .Locked = False
                .FormulaHidden = False
                With .Interior
                    .ColorIndex = 0
                    .Pattern = xlNone
                End With
            End With
            ActiveSheet.Protect UserInterfaceOnly:=True

+ 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