FrankMcNally
Board Regular
- Joined
- Nov 14, 2014
- Messages
- 71
Hello All,
I know this goes against programming logic, but I have a macro that gets ran everyday. For about a month it ran no problem and now for the last week and a half it gets 'hung-up' 5/6 of the way through the program. Below is the Code, I've put in orange where it stops every-time. I'm getting the Error Message: "Run-time Error '9': Subscript out of range" when I go to Watch Expression I get "NextFree = Sheets("Sheet1").Range("x6:x" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row <subscript out="" of="" range=""> Variant/Integer Module1.Create_New_BalanceSheet". I tried to "skip over it (Shift-F8) but it wouldn't let me.
ANY and ALL help is appreciated
</subscript>
I know this goes against programming logic, but I have a macro that gets ran everyday. For about a month it ran no problem and now for the last week and a half it gets 'hung-up' 5/6 of the way through the program. Below is the Code, I've put in orange where it stops every-time. I'm getting the Error Message: "Run-time Error '9': Subscript out of range" when I go to Watch Expression I get "NextFree = Sheets("Sheet1").Range("x6:x" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row <subscript out="" of="" range=""> Variant/Integer Module1.Create_New_BalanceSheet". I tried to "skip over it (Shift-F8) but it wouldn't let me.
ANY and ALL help is appreciated
Code:
Sub Create_New_BalanceSheet()'
' New_Entry Macro
'
Dim New_Reconciliation As String 'This is the new Directory and Name for the Current Workbook i.e. J:\year\month\New_Reconciliation021115
Dim Cadet As String 'This is the Directory and Name of one of the reference files i.e. J:\year\month\Cadet
Dim Final_Reconciliation As String
Dim FB_Detail_Report As String 'This is the Sheet Name in the File "Cadet
Dim CAB_Debit As String 'this is the Directory and Name of another reference file i.e J:\year\month\CAB_Debit
Dim CA_Credit As String 'this is the Directory and Name of another reference file i.e J:\year\month\CA_Credit
Dim CDR_Entries As String 'this is the Directory and Name of another reference file i.e J:\year\month\CDR_Entries
Dim CadetWkbk As Workbook
Dim CABWkbk As Workbook
Dim CAWkbk As Workbook
Dim CDRWkbk As Workbook
Dim Last_601 As String 'this is a Cell in the file J:\year\month\New_Reconciliation021115 referred to as Named Range ("New_Reconciliation")
Dim New_601 As String ' this will be the New 601 found after searching through file J:\year\month\Cadet which is reffered to as Named Range ("Cadet")
Dim Last_616 As String 'this is a Cell in the file J:\year\month\New_Reconciliation021115 referred to as Named Range ("New_Reconciliation")
Dim New_616 As String ' this will be the New 616 found after searching through file J:\year\month\Cadet which is reffered to as Named Range ("Cadet")
Dim Last_617 As String 'this is a Cell in the file J:\year\month\New_Reconciliation021115 referred to as Named Range ("New_Reconciliation")
Dim New_617 As String ' this will be the New 617 found after searching through file J:\year\month\Cadet which is reffered to as Named Range ("Cadet")
Dim ActivePeriod As String
Dim I As Long
Dim J As Long
Dim r As Long, TopRow As Long
Dim CDR_Count As Long
Application.ScreenUpdating = False
If MsgBox("Do you want to Reconcile the 601 for " & Format(Now(), "mmmm") & " " & Day(Date) & "?", vbYesNo) = vbYes Then
ActivePeriod = Application.InputBox("What Financial Period are you working in?")
Worksheets(2).Range("a16").Copy
Worksheets(1).Range("Update").PasteSpecial xlPasteValues
Worksheets(1).Range("FreeBalance_Total").Select
For J = 1 To 25
ActiveCell.Offset(-1, 0).EntireRow.Insert
Next J
Columns("A:A").NumberFormat = "mmm - dd"
Worksheets(2).Range("L3") = ActivePeriod
Worksheets(2).Range("b20:b26").Copy
Worksheets(2).Range("J20:J26").PasteSpecial xlPasteValues
ActiveWorkbook.SaveAs Range("New_Reconciliation")
Var1 = ActiveWorkbook.Name
Workbooks.Open Filename:=Range("Cadet").Value
Set CadetWkbk = ActiveWorkbook
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit
Columns("F:H").Select
Columns("F:H").NumberFormat = "#,##0.00_);(#,##0.00)"
LastRow = Cells(Rows.Count, 6).End(xlUp).Row
Cells(LastRow + 2, 6).Formula = "=sum(F2:F" & LastRow + 1 & ")"
Cells(LastRow + 2, 4).Value = "Today"
Cells(LastRow + 3, 4).Value = "Yesterday"
Cells(LastRow + 3, 6).Value = ThisWorkbook.Sheets("Sheet1").Range("Daily_Total_Update")
Cells(LastRow, 7).Copy
Cells(LastRow + 5, 6).PasteSpecial xlPasteValues
Cells(LastRow + 6, 4).Value = "Total"
Cells(LastRow + 6, 6).FormulaR1C1 = "=sum(R[-3]C:R[-4]C)"
Cells(LastRow + 8, 4).Value = "Difference"
Cells(LastRow + 8, 6).FormulaR1C1 = "=R[-2]c-R[-3]c"
FinalCell = Range("G" & Rows.Count).End(xlUp).Row
Range("G" & FinalCell).Copy
Workbooks(Var1).Sheets("Sheet1").Range("Daily_Total_Update").PasteSpecial xlPasteValues
' Code to Insert Blank Lines
Dim rowAmnt As Long
Dim mcol As String
Dim irow As Long
' find last used cell in Column A
rowAmnt = Cells(Rows.Count, "A").End(xlUp).Row
' insert rows by looping from bottom
For irow = Row To 2 Step -1
'if current value is not same as the current row being tested
If Cells(irow, 3) = "PAYMNT" Then
If Cells(irow + 1, 3) = "PAYMNT" Then
If Cells(irow, 5) <> Cells(irow + 1, 5) Then
Cells(irow + 1, 3).Select
ActiveCell.EntireRow.Insert
ActiveCell.EntireRow.Insert
End If
Else
Cells(irow + 1, 3).Select
ActiveCell.EntireRow.Insert
ActiveCell.EntireRow.Insert
End If
End If
If Cells(irow, 3) <> "PAYMNT" Then
If Cells(irow + 1, 3) = "PAYMNT" Then
Cells(irow + 1, 3).Select
ActiveCell.EntireRow.Insert
End If
End If
Next irow
' Code to sum Columns
RowCount = 2
TopRow = 2
StepRow = 1
While Cells(RowCount, 5) <> ""
If Cells(RowCount, 3) = "PAYMNT" Then
If Cells(RowCount, 5) <> Cells(RowCount + 1, 5) Then
Rows(RowCount + 1).Insert
Rows(RowCount + 1).Insert
Cells(RowCount + 1, 6).Formula = "=SUM(F" & TopRow & ":F" & RowCount & ")"
Range(Cells(RowCount, 1), Cells(RowCount, 5)).Copy
Cells(RowCount + 1, 1).PasteSpecial Paste:=xlPasteValues
Cells(RowCount, 7).Copy
Cells(RowCount + 1, 7).PasteSpecial Paste:=xlPasteValues
Cells(RowCount + 1, 6).Font.Bold = True
ActiveCell.EntireRow.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Rows(1 + StepRow & ":" & ActiveCell.Row - 1).Delete
RowCount = StepRow + 2
TopRow = RowCount + 1
StepRow = StepRow + 1
End If
Else
If Cells(RowCount, 3) <> Cells(RowCount + 1, 3) Then
Rows(RowCount + 1).Insert
RowCount = RowCount + 1
StepRow = StepRow + 1
Else
End If
TopRow = RowCount + 1
StepRow = StepRow + 1
End If
RowCount = RowCount + 1
Wend
' Code to put in Current Date
ThisWorkbook.Activate
Cells(Rows.Count, "e").End(xlUp).Select
ActiveCell.Offset(Rowoffset:=2, columnOffset:=-4).Activate
ActiveCell.Value = Date
' Code to Find and then Delete old 'Last_601' Line from Cadet
Dim wb As Workbook 'Cadet Workbook
Dim bk As Workbook 'Recon Workbook
Dim ws As Worksheet 'Cadet Worksheet
Dim sh As Worksheet 'Recon Worksheet
Dim s As String
Dim s_616 As String
Dim s_617 As String
Dim Fnd As Range '601 Range in Cadet
Dim Fnd_616 As Range '616 Range in Cadet
Dim Fnd_617 As Range '616 Range in Cadet
Dim rowNumber As Integer
Set wb = CadetWkbk
Set bk = ThisWorkbook
Set ws = wb.Sheets("FB_Detail_Report")
Set sh = bk.Sheets("Sheet1")
s = sh.Range("Last_601")
s_616 = sh.Range("Last_616")
s_617 = sh.Range("Last_617")
Set Fnd = ws.Columns(2).Find(What:=s, LookAt:=xlWhole)
If Not Fnd Is Nothing Then
rowNumber = Fnd.Row
If rowNumber <> 2 Then
ws.Rows("2:" & rowNumber).EntireRow.Delete
End If
End If
Set Fnd_616 = ws.Columns(2).Find(What:=s_616, LookAt:=xlWhole)
If Not Fnd_616 Is Nothing Then
rowNumber = Fnd_616.Row
If rowNumber <> 2 Then
ws.Rows(rowNumber).EntireRow.Delete
End If
End If
Set Fnd_617 = ws.Columns(2).Find(What:=s_617, LookAt:=xlWhole)
If Not Fnd_617 Is Nothing Then
rowNumber = Fnd_617.Row
If rowNumber <> 2 Then
ws.Rows(rowNumber).EntireRow.Delete
End If
End If
' Code to put Cadet Entries onto Balancesheet
Dim LastCadetRow As Long
With ws
LastCadetRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
ws.Range("A2:f" & LastCadetRow).Copy
Cells(Rows.Count, "e").End(xlUp).Select
ActiveCell.Offset(Rowoffset:=2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
CadetWkbk.Save
CadetWkbk.Close
' Code to put FreeBalance Credit (Negative) into sheet
Workbooks.Open Filename:=Range("CA_Credit").Value
Set CAWkbk = ActiveWorkbook
Columns("C:C").NumberFormat = "#,##0.00_);(#,##0.00)"
Range("C2").Copy
ThisWorkbook.Activate
Range("FB_Negative").PasteSpecial xlPasteValues
CAWkbk.Save
CAWkbk.Close
' Code to put RGGL Debit (Positive) into sheet
Workbooks.Open Filename:=Range("CAB_Debit").Value
Set CABWkbk = ActiveWorkbook
Columns("b:b").NumberFormat = "#,##0.00_);(#,##0.00)"
Range("B2").Copy
ThisWorkbook.Activate
Range("RGGL_Positive").PasteSpecial xlPasteValues
CABWkbk.Save
CABWkbk.Close
Workbooks.Open Filename:=Range("CDR_Entries").Value
Set CDRWkbk = ActiveWorkbook
Columns("c:c").NumberFormat = "#,##0.00_);(#,##0.00)"
Range("a1").Select
Do Until IsEmpty(ActiveCell)
RowCount = RowCount + 1
ActiveCell.Offset(1, 0).Select
Loop
Range("A1:D" & RowCount).Select
ActiveWorkbook.Worksheets("_CDR1001").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("_CDR1001").Sort.SortFields.Add Key:=Range("D2:D11"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("_CDR1001").Sort.SortFields.Add Key:=Range("A2:A11"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("_CDR1001").Sort
.SetRange Range("A1:D" & RowCount)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
For CDR_Count = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(CDR_Count, 4) = "CR" Then
' This moves Credits for Accounts 15, 35, etc to RG-GL Side and makes them Negative
If Cells(CDR_Count, 1) < 132 Then
Range("A" & CDR_Count & ",C" & J).Copy
NextFree = Sheets("Sheet1").Range("x6:x" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("x" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("x" & NextFree).PasteSpecial Paste:=xlPasteFormats
If Sheets("Sheet1").Range("y" & NextFree) > 0 Then
Sheets("Sheet1").Range("y" & NextFree).Value = (Sheets("Sheet1").Range("y" & NextFree).Value) * -1
End If
End If
' This moves Credits to the Account 132 to the RG-GL side and makes Negative
If Cells(CDR_Count, 1) = 132 Then
Range("C" & CDR_Count).Copy
[COLOR=#ffa500] NextFree = Sheets("Sheet1").Range("AC6:AC" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row[/COLOR]
Sheets("Sheet1").Range("x" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("AC" & NextFree).PasteSpecial Paste:=xlPasteFormats
If Sheets("Sheet1").Range("AC" & NextFree) > 0 Then
Sheets("Sheet1").Range("AC" & NextFree).Value = (Sheets("Sheet1").Range("AC" & NextFree).Value) * -1
End If
End If
' This moves Credits to the Account 401-409 to the RG-GL side and makes Negative
If Cells(CDR_Count, 1) > 132 And Cells(CDR_Count, 1) < 500 Then
Range("C" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("AG6:AG" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("AG" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("AG" & NextFree).PasteSpecial Paste:=xlPasteFormats
If Sheets("Sheet1").Range("AG" & NextFree) > 0 Then
Sheets("Sheet1").Range("AG" & NextFree).Value = (Sheets("Sheet1").Range("AG" & NextFree).Value) * -1
End If
End If
' This moves Credits for COE, CMC, CME to the RG-GL side and makes Negative
If Cells(CDR_Count, 1) > 500 Then
Range("C" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("Ak6:AK" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("AK" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("AK" & NextFree).PasteSpecial Paste:=xlPasteFormats
If Sheets("Sheet1").Range("Ak" & NextFree) > 0 Then
Sheets("Sheet1").Range("Ak" & NextFree).Value = (Sheets("Sheet1").Range("Ak" & NextFree).Value) * -1
End If
Range("B" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("Al6:Al" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("Al" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
End If
Else
' This moves Debits for Accounts 15, 35, etc to RG-GL Side
If Cells(CDR_Count, 1) < 132 Then
Range("A" & CDR_Count & ",C" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("M6:M" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("M" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("M" & NextFree).PasteSpecial Paste:=xlPasteFormats
End If
' This moves Debits for Accounts 132 etc to RG-GL Side
If Cells(CDR_Count, 1) = 132 Then
Range("C" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("R6:R" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("R" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("R" & NextFree).PasteSpecial Paste:=xlPasteFormats
End If
' This moves Debits for Accounts 401-409 etc to RG-GL Side
If Cells(CDR_Count, 1) > 132 Then
Range("C" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("V6:V" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("V" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("V" & NextFree).PasteSpecial Paste:=xlPasteFormats
End If
' This moves Debits for COE, CMC, CME to the RG-GL side
If Cells(CDR_Count, 1) > 500 Then
Range("C" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("Ak6:AK" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("AK" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Sheets("Sheet1").Range("AK" & NextFree).PasteSpecial Paste:=xlPasteFormats
Range("B" & CDR_Count).Copy
NextFree = Sheets("Sheet1").Range("Al6:Al" & J).Cells.SpecialCells(xlCellTypeBlanks).Row
Sheets("Sheet1").Range("Al" & NextFree).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
End If
End If
Next
End If
CDRWkbk.Save
CDRWkbk.Close
Range("A7").Select
' Find and replace New Last_601
Dim FindString As String
Dim rng As Range
FindString = "601"
With Sheets("Sheet1").Range("E:E")
Set rng = .Find(What:=FindString, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
ActiveCell.Offset(columnOffset:=1).Copy
Range("last_601").PasteSpecial
Else
End If
End With
' Find and Replace New Last_601_Value
FindString = "601"
With Sheets("Sheet1").Range("E:E")
Set rng = .Find(What:=FindString, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
ActiveCell.Offset(columnOffset:=5).Copy
Range("Last_601_Amount").PasteSpecial
Else
End If
End With
'Find and replace New Last_606
FindString = "606"
With Sheets("Sheet1").Range("E:E")
Set rng = .Find(What:=FindString, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
ActiveCell.Offset(columnOffset:=1).Copy
Range("last_606").PasteSpecial
End If
End With
' Find and Replace New Last_616_Value
FindString = "616"
With Sheets("Sheet1").Range("E:E")
Set rng = .Find(What:=FindString, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
ActiveCell.Offset(columnOffset:=5).Copy
Range("Last_616_Amount").PasteSpecial
End If
End With
'Find and replace New Last_617
FindString = "617"
With Sheets("Sheet1").Range("E:E")
Set rng = .Find(What:=FindString, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
ActiveCell.Offset(columnOffset:=1).Copy
Range("last_617").PasteSpecial
End If
End With
' Find and Replace New Last_617_Value
FindString = "617"
With Sheets("Sheet1").Range("E:E")
Set rng = .Find(What:=FindString, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
ActiveCell.Offset(columnOffset:=5).Copy
Range("Last_617_Amount").PasteSpecial
End If
End With
End Sub
Last edited: