PC Review


Reply
Thread Tools Rate Thread

Conditional formatting crashes macro

 
 
Rick S.
Guest
Posts: n/a
 
      28th Feb 2008
How can conditional formatting crash this macro?
It will fail at "Calculate" when some conditional formatting is used,
unfortunately I have not found the exact formatting that causes the crash. I
can circumvent the crash if I clear all conditionals prior to running the
macro. However it has adverse affects as well, like failing to copy
worksheets to the proper location of each other.

I can supply a sample workbook with all conditional formatting and releavant
macros to any who wish to help. The macro is a printing function.
IPI = In-Process Inspection (report).

'======
Sub PrintIPI()
'
' PrintIPI Macro
' Macro date 03/08/07 by L Roach
'This macro prints and sorts the correct number of copies of the IPI based on
'the number of parts on the job.

Dim NumCopies As Long, WhereToPaste As Long, PasteCopy As Long, WhatOp As Long
Dim GetName() As String, LastPage As String, OpName As String
Dim objSht As Worksheet
On Error GoTo SORRY
Calculate
'If there are more than 50 parts add the required sheets
If Sheets("Master Sheet").Range("B21").Value > 50 Then
NumCopies = Round((Sheets("Master Sheet").Range("B21").Value / 50) +
0.5) - 1
For Each objSht In ActiveWorkbook.Worksheets
For PasteCopy = 1 To NumCopies
'Name the pages that have been added for extra parts
If InStr(UCase(objSht.Name), "OP") <> 0 Then
GetName = Split(Trim(Replace((Replace(UCase(objSht.Name),
"OP", "")), "-", " ")), " ")
OpName = GetName(0)
For WhatOp = objSht.Index To Sheets.Count
If InStr(Sheets(WhatOp).Name, OpName) < 1 Then Exit For
If InStr(Sheets(WhatOp).Name, LastPage & " (" &
PasteCopy + 1 & ")") > 0 Then
WhatOp = WhatOp + 1
Exit For
End If
Next WhatOp
'Fix the wording on the in process sheets
Sheets(objSht.Name).Copy after:=Sheets(WhatOp - 1)
Cells.Replace What:="Oper F.A.", Replacement:="I.P.",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False
Cells.Replace What:="Insp F.A.", Replacement:="I.P.",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False
Cells.Replace What:="Co Op F.A.", Replacement:="I.P.",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False
End If
Next PasteCopy
LastPage = objSht.Name
Next objSht
End If
Application.CutCopyMode = False
ActiveWorkbook.PrintOut
ActiveWindow.Close SaveChanges:=False
Exit Sub
SORRY:
MsgBox "Failed to print IPI", , "Sorry... Had an error."
End Sub
'======
--
Regards

VBA.Newb.Confused
XP Pro
Office 2007

 
Reply With Quote
 
 
 
 
Rick S.
Guest
Posts: n/a
 
      29th Feb 2008
This is strange and may be helpful for others.
1. The "conditional Formatting" was not causing the problem, it only
apeared that way.
2. This is a simple matter of worksheet naming. In Excel 2007 it appears
that worksheet names can not conflict with the manner that Excel renames when
making coppies. Example: If I name a worksheet "OP 10 (1)" this is a direct
conflict with Excel naming.
If the worksheet is named "OP 10-1" when you make a copy Excel renames to
"OP 10-1 (1)". Hence Excel 2007 reads the first worksheet I named "OP 10
(1)" as a iteration(?) and begins the copy name at "OP 10 (2)" this
apparently causes a counting conflict which is the problem that occurred with
my macro.

HTH others.

--
Regards

VBA.Newb.Confused
XP Pro
Office 2007



"Rick S." wrote:

> How can conditional formatting crash this macro?
> It will fail at "Calculate" when some conditional formatting is used,
> unfortunately I have not found the exact formatting that causes the crash. I
> can circumvent the crash if I clear all conditionals prior to running the
> macro. However it has adverse affects as well, like failing to copy
> worksheets to the proper location of each other.
>
> I can supply a sample workbook with all conditional formatting and releavant
> macros to any who wish to help. The macro is a printing function.
> IPI = In-Process Inspection (report).
>
> '======
> Sub PrintIPI()
> '
> ' PrintIPI Macro
> ' Macro date 03/08/07 by L Roach
> 'This macro prints and sorts the correct number of copies of the IPI based on
> 'the number of parts on the job.
>
> Dim NumCopies As Long, WhereToPaste As Long, PasteCopy As Long, WhatOp As Long
> Dim GetName() As String, LastPage As String, OpName As String
> Dim objSht As Worksheet
> On Error GoTo SORRY
> Calculate
> 'If there are more than 50 parts add the required sheets
> If Sheets("Master Sheet").Range("B21").Value > 50 Then
> NumCopies = Round((Sheets("Master Sheet").Range("B21").Value / 50) +
> 0.5) - 1
> For Each objSht In ActiveWorkbook.Worksheets
> For PasteCopy = 1 To NumCopies
> 'Name the pages that have been added for extra parts
> If InStr(UCase(objSht.Name), "OP") <> 0 Then
> GetName = Split(Trim(Replace((Replace(UCase(objSht.Name),
> "OP", "")), "-", " ")), " ")
> OpName = GetName(0)
> For WhatOp = objSht.Index To Sheets.Count
> If InStr(Sheets(WhatOp).Name, OpName) < 1 Then Exit For
> If InStr(Sheets(WhatOp).Name, LastPage & " (" &
> PasteCopy + 1 & ")") > 0 Then
> WhatOp = WhatOp + 1
> Exit For
> End If
> Next WhatOp
> 'Fix the wording on the in process sheets
> Sheets(objSht.Name).Copy after:=Sheets(WhatOp - 1)
> Cells.Replace What:="Oper F.A.", Replacement:="I.P.",
> LookAt:=xlPart, _
> SearchOrder:=xlByRows, MatchCase:=False,
> SearchFormat:=False, _
> ReplaceFormat:=False
> Cells.Replace What:="Insp F.A.", Replacement:="I.P.",
> LookAt:=xlPart, _
> SearchOrder:=xlByRows, MatchCase:=False,
> SearchFormat:=False, _
> ReplaceFormat:=False
> Cells.Replace What:="Co Op F.A.", Replacement:="I.P.",
> LookAt:=xlPart, _
> SearchOrder:=xlByRows, MatchCase:=False,
> SearchFormat:=False, _
> ReplaceFormat:=False
> End If
> Next PasteCopy
> LastPage = objSht.Name
> Next objSht
> End If
> Application.CutCopyMode = False
> ActiveWorkbook.PrintOut
> ActiveWindow.Close SaveChanges:=False
> Exit Sub
> SORRY:
> MsgBox "Failed to print IPI", , "Sorry... Had an error."
> End Sub
> '======
> --
> Regards
>
> VBA.Newb.Confused
> XP Pro
> Office 2007
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting Macro? =?Utf-8?B?bXlkb2dwZWFudXQ=?= Microsoft Excel Programming 3 19th Oct 2007 06:23 PM
Conditional Formatting Macro =?Utf-8?B?RGFyZW4=?= Microsoft Excel Misc 2 27th Jun 2007 10:58 PM
Conditional formatting macro K1KKKA Microsoft Excel Discussion 1 27th Apr 2007 02:57 PM
Conditional Formatting in Macro shantanu oak Microsoft Excel Misc 2 14th Jul 2006 01:11 PM
macro for conditional formatting Microsoft Excel Programming 8 27th Oct 2003 08:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.