+ Reply to Thread
Results 1 to 15 of 15

Macro stopped working.

Hybrid View

joleen Macro stopped working. 06-04-2011, 07:14 AM
snb Re: Macro stopped working. 06-04-2011, 07:23 AM
joleen Re: Macro stopped working. 06-04-2011, 08:51 AM
teylyn Re: Macro stopped working. 06-04-2011, 07:24 AM
joleen Re: Macro stopped working. 06-04-2011, 08:46 AM
snb Re: Macro stopped working. 06-04-2011, 08:53 AM
teylyn Re: Macro stopped working. 06-04-2011, 09:06 AM
joleen Re: Macro stopped working. 06-04-2011, 09:16 AM
snb Re: Macro stopped working. 06-04-2011, 09:41 AM
joleen Re: Macro stopped working. 06-05-2011, 05:39 AM
royUK Re: Macro stopped working. 06-05-2011, 05:47 AM
joleen Re: Macro stopped working. 06-05-2011, 06:16 AM
royUK Re: Macro stopped working. 06-05-2011, 01:13 PM
joleen Re: Macro stopped working. 06-06-2011, 05:05 AM
royUK Re: Macro stopped working. 06-06-2011, 05:37 AM
  1. #1
    Registered User
    Join Date
    06-04-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Macro stopped working.

    Hi,

    I am using this macro to print selected sheets from a workbook with 229 sheets.
    It should only print the sheets with qualifying data in two specific cells. It worked perfectly for about 2 weeks. I went home on Tuesday and everything was fine, came back on Thursday and I am getting a runtime 13 miss match error.

    Any thoughts?

    Sub macroprint()
    Dim Sh As Worksheet
        Dim Arr() As String
        Dim N As Integer
        N = 0
        For Each Sh In ActiveWorkbook.Worksheets
            If Sh.Visible = xlSheetVisible And Sh.Range("E1").Value > "40544" And Sh.Range("C2").Value <> "Occupied" Then
                N = N + 1
                ReDim Preserve Arr(1 To N)
                Arr(N) = Sh.Name
            End If
        Next
        If N = 0 Then
            MsgBox "No Vacant Dirty", vbExclamation
            Exit Sub
        End If
        With ActiveWorkbook
            .Worksheets(Arr).PrintOut
          
        End With
        
        End Sub
    Thank you
    Last edited by joleen; 06-05-2011 at 06:27 AM. Reason: Solved

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro stopped working.

    Why did you go home in the first place .... ?

    I'd try:

    Sub macroprint()
      For Each Sh In ActiveWorkbook.sheets
        If Sh.Visible = -1 And Sh.Range("E1").Value > 40544 And Sh.Range("C2").Value <> "Occupied" Then c01 =c01 & "|" & sh.name
      Next
    
      If isempty(c01) Then
        MsgBox "No Vacant Dirty", vbExclamation
      else
        activeworkbook.sheets(split(mid(c01,2),"|")).printout
      End If
    End Sub
    Last edited by snb; 06-04-2011 at 08:58 AM.



  3. #3
    Registered User
    Join Date
    06-04-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro stopped working.

    I tried the new code. Thank you snb,

    But I am still receiving the same error.
    Last edited by joleen; 06-04-2011 at 08:53 AM. Reason: to clarify what post I was responding to

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Macro stopped working.

    If you click Debug when the error message appears, which line of the code is highlighted?

  5. #5
    Registered User
    Join Date
    06-04-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro stopped working.

    The line that is highlighted is:

         If Sh.Visible = xlSheetVisible And Sh.Range("E1").Value > "40544" And Sh.Range("C2").Value <> "Occupied" Then

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro stopped working.

    I don't think my suggestion will produce that error.

    Sh.Range("E1").Value > "40544"
    is the culprit.

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Macro stopped working.

    @snb

    I don't think my suggestion will produce that error.
    apparently it does. Otherwise the asker would not report it. Instead of tagging the component

    Sh.Range("E1").Value > "40544"
    as "the culprit", do you have a suggestion about how to troubleshoot the issue?

  8. #8
    Registered User
    Join Date
    06-04-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro stopped working.

    I am using a the E1 cell on each sheet to reflect dates in cell A4 as just a number. When I had

    If Sh.Visible = xlSheetVisible And Sh.Range("A4").Value <> "" And Sh.Range("C2").Value <> "Occupied" Then
    I always ended up with sheets printed out where A4 was empty.

    I don't know if that helps at all.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro stopped working.

    Sub macroprint()
      For Each Sh In ActiveWorkbook.sheets
        If Sh.Visible = -1 And val(Sh.Range("E1").Value) > 40544 And Sh.Range("C2").Value <> "Occupied" Then c01 =c01 & "|" & sh.name
      Next
    
      If isempty(c01) Then
        MsgBox "No Vacant Dirty", vbExclamation
      else
        activeworkbook.sheets(split(mid(c01,2),"|")).printout
      End If
    End Sub
    Last edited by snb; 06-04-2011 at 10:11 AM.

  10. #10
    Registered User
    Join Date
    06-04-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro stopped working.

    With

    Sub macroprint()
      For Each Sh In ActiveWorkbook.sheets
        If Sh.Visible = -1 And val(Sh.Range("E1").Value) > 40544 And Sh.Range("C2").Value <> "Occupied" Then c01 =c01 & "|" & sh.name
      Next
    
      If isempty(c01) Then
        MsgBox "No Vacant Dirty", vbExclamation
      else
        activeworkbook.sheets(split(mid(c01,2),"|")).printout
      End If
    End Sub
    I receive a Runtime error '438' Object does not support this property or method.

    And still the line highlighted by the debugger is basically the same.

        If Sh.Visible = -1 And Val(Sh.Range("E1").Value) > 40544 And Sh.Range("C2").Value <> "Occupied" Then c01 = c01 & "|" & Sh.Name
    This file is moved back and forth from a sharepoint site everyday. Could that be causing corruption problems?

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro stopped working.

    Has anything in the cells that are checked been changed? This might be on just one sheet
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  12. #12
    Registered User
    Join Date
    06-04-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro stopped working.

    I did a full manual check and yes actual a lot had changed.

    1) On almost all of the sheets cell A1 was "blank" instead of "empty" so instead of showing a zero in E1 it was blank
    2)I found a whole bunch of sheets were the formating had been changed from General to a custom date.
    3) There was one sheet where instead of E1 referencing A4 it had a REF# error.

    My guess is on my days off my co-worker cleared the data by deleting the whole row and not just contents of the cells.

    Everything is working now.
    Thank you so much for your help.

    Now if I can just figure out how to keep the empty cells empty I'll be in great shape.

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro stopped working.

    Have you used sheet protection to lock cells?

  14. #14
    Registered User
    Join Date
    06-04-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro stopped working.

    I have locked most of the cells in the workbook. However I haven't locked anything that needs to have manual data entry. I was under the impression that there is no way to prevent a cell from being deleted and still have it open for data adjustment.

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro stopped working.

    You might be able to protect the workbook structure using Workbook Protection.

    Naturally, make sure you have a back up file at all times

+ 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