Hi there,
This sheet below is a sheet within a workbook with many sheets like this one. The formatting of the sheets will always remain the same. The code works great for what I first asked for but then a change occured. The code, should read everything the same way but add an if statement for a grand total. Some sheets have grand totals and some do not. If there are
no grand totals in column c then go on and read for account total. If grand total
is found transfer the grandtotal and move to the next department macro.
Example of a sheet
[TABLE="width: 986"]
<tbody>[TR]
[TD="colspan: 3"]Department 60 Adult Program Department[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]ACCOUNT#: 1-026-60-00000-3344[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]MEMBER NUMBER[/TD]
[TD]MEMBER NAME[/TD]
[TD]TRN DATE[/TD]
[TD]0 -30 DAYS[/TD]
[TD]31-60 DAYS[/TD]
[TD]61-90 DAYS[/TD]
[TD]OVER 90 DAYS[/TD]
[TD]PAST DUE[/TD]
[/TR]
[TR]
[TD]026-000175813-02[/TD]
[TD]Brea, Hanna[/TD]
[TD="align: right"]1/3/2017[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$325.00[/TD]
[TD="align: right"]$325.00[/TD]
[/TR]
[TR]
[TD]026-000144629-02[/TD]
[TD]Garrelick, Jillia[/TD]
[TD="align: right"]1/18/2017[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$425.00[/TD]
[TD="align: right"]$425.00[/TD]
[/TR]
[TR]
[TD]026-000144629-03[/TD]
[TD]Garrelick, Lilah[/TD]
[TD="align: right"]1/18/2017[/TD]
[TD="align: right"]$425.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$425.00[/TD]
[/TR]
[TR]
[TD]026-000087880-02[/TD]
[TD]Roque, Kaiden[/TD]
[TD="align: right"]12/19/2016[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$775.00[/TD]
[TD="align: right"]$775.00[/TD]
[/TR]
[TR]
[TD]026-000087880-03[/TD]
[TD]Roque, Kelsey[/TD]
[TD="align: right"]12/19/2016[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$775.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$775.00[/TD]
[/TR]
[TR]
[TD]026-000087880-03[/TD]
[TD]Roque, Kelsey[/TD]
[TD="align: right"]12/19/2016[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$1,230.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$1,230.00[/TD]
[/TR]
[TR]
[TD]026-000087880-03[/TD]
[TD]Roque, Kelsey[/TD]
[TD="align: right"]12/19/2016[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$600.00[/TD]
[TD="align: right"]$600.00[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]ACCOUNT TOTAL[/TD]
[TD][/TD]
[TD="align: right"]$425.00[/TD]
[TD="align: right"]$2,005.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$2,125.00[/TD]
[TD="align: right"]$4,555.00[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"]Department 65 Visual and Performing Art[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]ACCOUNT#: 1-026-65-00000-3346[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]MEMBER NUMBER[/TD]
[TD]MEMBER NAME[/TD]
[TD]TRN DATE[/TD]
[TD]0 -30 DAYS[/TD]
[TD]31-60 DAYS[/TD]
[TD]61-90 DAYS[/TD]
[TD]OVER 90 DAYS[/TD]
[TD]PAST DUE[/TD]
[/TR]
[TR]
[TD]026-000173132-00[/TD]
[TD]Coursehorse inc.[/TD]
[TD="align: right"]11/4/2016[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$227.17[/TD]
[TD="align: right"]$227.17[/TD]
[/TR]
[TR]
[TD]026-000173132-00[/TD]
[TD]Coursehorse inc.[/TD]
[TD="align: right"]1/1/2017[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$209.63[/TD]
[TD="align: right"]$209.63[/TD]
[/TR]
[TR]
[TD]026-000173132-00[/TD]
[TD]Coursehorse inc.[/TD]
[TD="align: right"]1/1/2017[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$208.07[/TD]
[TD="align: right"]$208.07[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]ACCOUNT TOTAL[/TD]
[TD]Grand Total[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$0.00[/TD]
[TD="align: right"]$644.87[/TD]
[TD="align: right"]$644.87[/TD]
[/TR]
</tbody>[/TABLE]
There are three macros that call each other but if one is called and that department is unavailable then it should jump to the next department.
Code:
Sub NumberTrans_Dep60()
Dim nlast As Long
Dim sht As Worksheet
Dim rng1 As Range
Dim rng2 As Range
Dim AcctTotRw As Long
Dim DeptRw As Long
Sheets("Amanda").Activate
Set sht = ActiveWorkbook.ActiveSheet
nlast = Cells(Rows.Count, "B").End(xlUp).Row
clast = Cells(Rows.Count, "C").End(xlUp).Row
Range("A1").Activate
Set rng1 = Range("A1:A" & nlast).Find("Department 60 Adult Program Department", Cells(1, ActiveCell.Column), xlValues, xlWhole, , xlNext)
DeptRw = rng1.Row
Range("C" & DeptRw).Activate
Set rng2 = Range("C" & DeptRw & ":C" & clast).Find("GRAND TOTAL", Cells(DeptRw, ActiveCell.Column), xlValues, xlWhole, , xlNext)
AccTotRw = rng2.Row
If AccToRw <> AccToRw Then
Range("B" & DeptRw).Activate
Set rng2 = Range("B" & DeptRw & ":B" & nlast).Find("ACCOUNT TOTAL", Cells(DeptRw, ActiveCell.Column), xlValues, xlWhole, , xlNext)
AccTotRw = rng2.Row
End If
Range("D" & AccTotRw).Resize(, 5).Copy
Sheets("AR SUMMARY").Range("C35").PasteSpecial xlPasteValues
NumberTrans_Dep63
End If
End Sub
Sub NumberTrans_Dep63()
Dim nlast As Long
Dim sht As Worksheet
Dim rng1 As Range
Dim rng2 As Range
Dim AcctTotRw As Long
Dim DeptRw As Long
Sheets("Amanda").Activate
Set sht = ActiveWorkbook.ActiveSheet
nlast = Cells(Rows.Count, "B").End(xlUp).Row
clast = Cells(Rows.Count, "C").End(xlUp).Row
Range("A1").Activate
Set rng1 = Range("A1:A" & nlast).Find("Department 63 Writers Voice, National Department", Cells(1, ActiveCell.Column), xlValues, xlWhole, , xlNext)
If Not rng1 Is Nothing Then
DeptRw = rng1.Row
Range("C" & DeptRw).Activate
Set rng2 = Range("C" & DeptRw & ":C" & clast).Find("GRAND TOTAL", Cells(DeptRw, ActiveCell.Column), xlValues, xlWhole, , xlNext)
AccTotRw = rng2.Row
If AccToRw <> AccToRw Then
Range("B" & DeptRw).Activate
Set rng2 = Range("B" & DeptRw & ":B" & nlast).Find("ACCOUNT TOTAL", Cells(DeptRw, ActiveCell.Column), xlValues, xlWhole, , xlNext)
AccTotRw = rng2.Row
End
Range("D" & AccTotRw).Resize(, 5).Copy
Sheets("AR SUMMARY").Range("C36").PasteSpecial xlPasteValues
End If
NumberTrans_Dep65
End Sub
Sub NumberTrans_Dep65()
Dim nlast As Long
Dim sht As Worksheet
Dim rng1 As Range
Dim rng2 As Range
Dim AcctTotRw As Long
Dim DeptRw As Long
Sheets("Amanda").Activate
Set sht = ActiveWorkbook.ActiveSheet
nlast = Cells(Rows.Count, "B").End(xlUp).Row
clast = Cells(Rows.Count, "C").End(xlUp).Row
Range("A1").Activate
Set rng1 = Range("A1:A" & nlast).Find("Department 65 Visual and Performing Art", Cells(1, ActiveCell.Column), xlValues, xlWhole, , xlNext)
If Not rng1 Is Nothing Then
DeptRw = rng1.Row
Range("C" & DeptRw).Activate
Set rng2 = Range("C" & DeptRw & ":C" & clast).Find("GRAND TOTAL", Cells(DeptRw, ActiveCell.Column), xlValues, xlWhole, , xlNext)
If Not rng2 Is Nothing Then
AccTotRw = rng2.Row
If AccToRw <> AccToRw Then
Range("B" & DeptRw).Activate
Set rng2 = Range("B" & DeptRw & ":B" & nlast).Find("ACCOUNT TOTAL", Cells(DeptRw, ActiveCell.Column), xlValues, xlWhole, , xlNext)
AccTotRw = rng2.Row
End If
Range("D" & AccTotRw).Resize(, 5).Copy
Sheets("AR SUMMARY").Range("C37").PasteSpecial xlPasteValues
End If
End If
End Sub
If you need more explanation please ask.