Sub CreateSheetsWithNames()
sheets("master").Cells.EntireColumn.Hidden = False
Dim firstrow As Range
Dim rcell As Range
Dim rcell2 As Range
Dim rcell3 As Range
Dim rcell4 As Range
Dim rcell5 As Range
Dim rcell6 As Range
Dim rcell7 As Range
Dim rcell9 As Range
Dim rcell10 As Range
Dim bcell As Range
Dim strnsearch As String
Dim lastrow As Long
Dim lastcolumn1 As Long
Dim y As Integer
With sheets("Master")
If .Range("b1") = vbNullString Then
lastcolumn1 = .Range("b1").End(xlDown).End(xlToRight).Column
Else
lastcolumn1 = .Range("b1").End(xlToRight).Column
End If
If .Range(Cells(1, lastcolumn1).Address) = "" Then
Set firstrow = .Range(Cells(1, lastcolumn1).Address).End(xlDown).Offset(0, 1)
Else: Set firstrow = .Range(Cells(1, lastcolumn1).Offset(0, 1).Address)
End If
For y = firstrow.Row To .Range("A100000").End(xlUp).Row
strnsearch = "Document Type"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Document Type'")
End
End If
strnsearch = "Expenses by LOA"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter2 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Expenses by LOA'")
End
End If
strnsearch = "Document Create Date"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter3 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Document Create Date'")
End
End If
strnsearch = "Departure Date"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter4 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Departure Date'")
End
End If
strnsearch = "Last AO Approved Date"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter5 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Last AO Approved Date'")
End
End If
strnsearch = "Total Trip Expenses"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter6 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Total Trip Expenses'")
End
End If
strnsearch = "TANum"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter7 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'TANum'")
End
End If
strnsearch = "Return Date"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter9 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Return Date'")
End
End If
strnsearch = "Current Status"
Set bcell = .UsedRange.Find(What:=strnsearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not bcell Is Nothing Then
bcellletter10 = Col_Letter(bcell.Column)
Else
MsgBox ("Please designate column 'Current Status'")
End
End If
LastLetter = Col_Letter(lastcolumn1)
clearletter = Col_Letter(firstrow.Column)
firstrow.Value = "AUTHORIZATIONS"
firstrow.Offset(0, 1).Value = "VOUCHERS"
firstrow.Offset(0, 2).Value = "LOCAL VOUCHERS"
firstrow.Offset(0, 3).Value = "Doc create date after departure date"
firstrow.Offset(0, 4).Value = "Travel Notice Given"
firstrow.Offset(0, 5).Value = "Voucher Create date over 5 days from Return"
firstrow.Offset(0, 6).Value = "Last AO approved Date before Doc Create Date"
firstrow.Offset(0, 7).Value = "Is Cancelled Trip Zero'd Out?"
firstrow.Offset(0, 8).Value = "Unliquidated Amount"
firstrow.Offset(0, 9).Value = "Unliquidated %"
Range(firstrow, firstrow.Offset(0, 9)).Font.Bold = True
For Each rcell In sheets("master").Range(bcellletter & y)
For Each rcell2 In sheets("master").Range(bcellletter2 & y)
If rcell.Value = "AUTH" Then
.Range(LastLetter & y).Offset(0, 1).Value = .Range(bcellletter2 & y).Value
End If
If rcell.Value = "VCH" Then
.Range(LastLetter & y).Offset(0, 2).Value = .Range(bcellletter2 & y).Value
End If
If rcell.Value = "LVCH" Then
.Range(LastLetter & y).Offset(0, 3).Value = .Range(bcellletter2 & y).Value
End If
Next
Next
For Each rcell In sheets("master").Range(bcellletter & y)
For Each rcell3 In sheets("master").Range(bcellletter3 & y)
For Each rcell4 In sheets("master").Range(bcellletter4 & y)
If rcell.Value = "AUTH" And rcell4.Value < rcell3.Value Then
.Range(LastLetter & y).Offset(0, 4).Value = "Error"
End If
Next
Next
Next
For Each rcell In sheets("master").Range(bcellletter & y)
For Each rcell6 In sheets("master").Range(bcellletter6 & y)
For Each rcell10 In sheets("master").Range(bcellletter10 & y)
If rcell.Value = "AUTH" Then
If rcell6.Value > 0 And rcell10.Value = "CANCELLED" Then
.Range(LastLetter & y).Offset(0, 7).Value = "Error"
End If
End If
Next
Next
Next
For Each rcell In sheets("master").Range(bcellletter & y)
For Each rcell3 In sheets("master").Range(bcellletter3 & y)
For Each rcell9 In sheets("master").Range(bcellletter9 & y)
If rcell.Value = "VCH" Or rcell.Value = "LVCH" Then
If rcell3.Value - rcell9.Value > 5 Then
.Range(LastLetter & y).Offset(0, 6).Value = "Error"
End If
End If
Next
Next
Next
For Each rcell2 In sheets("master").Range(bcellletter2 & y)
For Each rcell7 In sheets("master").Range(bcellletter7 & y)
If rcell7.Value = " " Or rcell7.Value = vbNullString And rcell2.Value > 0 Then
.Range(LastLetter & y).Offset(0, 8).Value = .Range(bcellletter2 & y)
.Range(LastLetter & y).Offset(0, 8).NumberFormat = "$#,##0.00"
End If
Next
Next
For Each rcell In sheets("master").Range(bcellletter & y)
For Each rcell3 In sheets("master").Range(bcellletter3 & y)
For Each rcell4 In sheets("master").Range(bcellletter4 & y)
If rcell.Value = "AUTH" Then
sheets("Master").Range(LastLetter & y).Offset(0, 5).Value = rcell4.Value - rcell3.Value
sheets("Master").Range(LastLetter & y).Offset(0, 5).HorizontalAlignment = xlCenter
End If
Next
Next
Next
Next
End With
End Sub
Bookmarks