Sub AcntNum()
Dim R As Integer 'original # of rows
Dim R1 As Integer 'new # of rows after sort
Dim i As Integer 'counter
Dim i2 As Integer 'counter 2
Dim S1 As Worksheet 'manipulation sheet definition
Set S1 = ThisWorkbook.Worksheets("1")
Dim Aws As Worksheet 'account worksheets
Dim RowB As Integer 'account start on sheet 1
Dim RowE As Integer 'account end on sheet 1
Dim RowL1 As Long 'last row on account worksheet before paste
Dim RowL2 As Long 'last row on account worksheet after paste
Dim Arr(1 To 18) As Variant 'account # array
Arr(1) = 7710541
Arr(2) = 7709192
Arr(3) = 7709207
Arr(4) = 7709223
Arr(5) = 7709231
Arr(6) = 7709249
Arr(7) = 7709265
Arr(8) = 7709273
Arr(9) = 7709299
Arr(10) = 7709312
Arr(11) = 7709338
Arr(12) = 7709354
Arr(13) = 7709370
Arr(14) = 7709388
Arr(15) = 7709396
Arr(16) = 7709401
Arr(17) = 7709435
Arr(18) = 7709540
S1.Cells.Delete
ThisWorkbook.Sheets("D").UsedRange.Copy
S1.Select
S1.Range("A1").Select
S1.Paste
Range("A1").Select
Selection.End(xlDown).Select
R = ActiveCell.Row
'move columns on sheet 1
Range("A:A,C:C,G:G").Delete
Range("C:C").Cut
Range("B:B").Insert
Range("G:G").Cut
Range("D:D").Insert
Range("C:C").Cut
Range("I:I").Insert
'eliminate non-tracked accounts
For i = 2 To R
If IsError(Application.Match(S1.Range("A" & i).Value, Arr, 0)) Then
S1.Range("A" & i).EntireRow.ClearContents
End If
Next i
'sort remaining values
S1.Range("A2:A" & R).EntireRow.Select
S1.Sort.SortFields.Clear
S1.Range("A2:A" & R).EntireRow.Sort key1:=S1.Range("B2"), Order1:=xlAscending
S1.Range("A1").Select
Selection.End(xlDown).Select
R1 = ActiveCell.Row
S1.Range("A1").Select
Application.CutCopyMode = False
'Type definition
For i = 2 To R1
If S1.Cells(i, 3) = "" Then
S1.Cells(i, 3).Value = Application.Proper(S1.Cells(i, 6).Value)
End If
Next i
S1.Range("C:C").Select
Selection.Replace what:=" Debit", replacement:=""
Selection.Replace what:=" Credit", replacement:=""
S1.Range("D:D").Select
Selection.Replace what:=" ", replacement:=""
'Transaction ID
S1.Range("F:F").Delete
S1.Range("G:G").Insert
S1.Range("G1").Value = "Transaction ID"
S1.Range("G2").Formula = "=A2&B2&D2&E2&C2"
S1.Range("G2:G" & R1).FillDown
'format Sheet 1
Cells.Select
With Selection
.ColumnWidth = 10
.RowHeight = 15
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlLeft
.Font.Name = "Arial Narrow"
.Font.Size = 8
End With
Range("G:G, H:H, I:I").ColumnWidth = 30
Range("B:B").NumberFormat = "m/d/yyyy"
Range("A:A, D:D").NumberFormat = "0"
Range("A:E").HorizontalAlignment = xlRight
Range("F:F").NumberFormat = "$#,##0.00_);($#,##0.00)"
Range("A1:J1").Font.Bold = True
Range("A1:H1").Borders(xlEdgeBottom).Weight = 3
Application.CutCopyMode = False
Stop
'paste sheet values
For i = 1 To 18
Set Aws = ThisWorkbook.Worksheets(CStr(Arr(i)))
Stop
RowL1 = Aws.Range("A65536").End(xlUp).Row
Stop
RowB = Application.Match(Arr(i), S1.Range("A:A"), 0)
Stop
RowE = RowB - 1 + Application.CountIf(S1.Range("A:A"), Arr(i))
Stop
RowL2 = RowL1 + RowE - RowB + 1
MsgBox "RowL1: " & RowL1
MsgBox "RowL2: " & RowL2
MsgBox "RowB: " & RowB
MsgBox "RowE: " & RowE
Stop
S1.Range("A" & RowB & ":A" & RowE).EntireRow.Copy
Aws.Select
Aws.Cells(RowL1 + 1, 1).Select
Aws.Paste
' remove duplicates
Aws.Range("I1").Formula = "=max(I2:I10000)"
Aws.Range("I2").Formula = "=IF(ISERROR(MATCH(G2,$G:$G,0)),0,MATCH(G2,$G:$G,0))"
Aws.Range("I2" & ":I" & RowL2).Select
Selection.FillDown
For i2 = 2 To RowL2
If Aws.Range("I" & i2).Value <> i2 Then
Aws.Range("I" & i2).EntireRow.ClearContents
End If
Next i2
Aws.Sort.SortFields.Clear
Aws.Range("A2:A" & RowL2).EntireRow.Sort key1:=Aws.Range("B2"), Order1:=xlAscending
Next i
End Sub