I am receiving an unhandled win32 exeption [256] when I execute my code. When I walk through the debugger line-by-line, I do not receive the error! It also goes away when I comment out two specific lines. These lines update the progress bar on a userform shown at the end of the loop. Very strange...any ideas? I have been starring at this too long.
This macro loops through a massive workbook and transposes monthly data from two sheets and merges them into the first active sheet.
This macro loops through a massive workbook and transposes monthly data from two sheets and merges them into the first active sheet.
Code:
Public Sub Main()
On Error GoTo ErrorMessage
Dim MainSheet As Worksheet, SisterSheet As Worksheet
Dim CurrentContract As Range, FirstSisterContract As Range, NextContract As Range
Dim NextSisterContract As Range
Dim SisterContractRow As Long, CurrentContractNum As Long
Dim SubSectionCount As Integer, CurSectionNum As Integer, DestinationIndex As Integer
Dim FirstRun As Integer, p As Integer
CurSectionNum = 1
FirstRun = 0
Set MainSheet = ActiveSheet
Set SisterSheet = Sheets(FindComSheet)
Set CurrentContract = GetCompanyCell
'------------------------------------------------------
'UI Initialization
'------------------------------------------------------
Application.ScreenUpdating = False
frmProgress.lblInfo.Visible = True
Call FindLastContract
frmProgress.lblInfo.Caption = "Transposing Data..."
'------------------------------------------------------
Do
CurrentContractNum = CurrentContract.Offset(0, -1).Value
SisterContractRow = FindContractRow(SisterSheet, CurrentContractNum)
EngageStopRow = True
Set NextContract = TransposeSingleContract(MainSheet, CurrentContract, SubSectionCount, True)
If SisterContractRow = -1 Then GoTo SkipMerge
EngageStopRow = False
Set NextSisterContract = TransposeSingleContract(SisterSheet, _
SisterSheet.Range("C" & SisterContractRow), SubSectionCount)
For p = 1 To UBound(SisterSubSectionHeaders, 2)
MainSheet.Activate
DestinationIndex = EvaluateSubSectionHeaders(SisterSubSectionHeaders(1, p))
If DestinationIndex > 0 And FirstRun > 0 Then
Call MergeContract(SisterSheet, _
Range("X" & SubSectionHeaders(2, DestinationIndex)), CurSectionNum)
ElseIf DestinationIndex > 0 Then
Call MergeContract(SisterSheet, _
Range("X" & SubSectionHeaders(2, DestinationIndex)), CurSectionNum, True)
FirstRun = 1
End If
SisterContractRow = NextSisterContract.Row
CurSectionNum = CurSectionNum + 1
Next
SkipMerge:
Set CurrentContract = NextContract
CurSectionNum = 1
SubSectionCount = 1
'--------------------------------------------------
'UI Update
'--------------------------------------------------
frmProgress.ProgressStyle1 (NextContract.Row / StopRow), True 'update progress bar
DoEvents
'--------------------------------------------------
Loop Until StopRow = NextContract.Row
[Code]