I am struggling to integrate a status bar into my VBA code below and make it work.
Does anyone have any ideas on how to fit this code in to the below code and make it work:
I believe the progress bar code should follow this format:
However I don't know how to integrate this into the below code so that it works:
Thanks.
</code>
Does anyone have any ideas on how to fit this code in to the below code and make it work:
I believe the progress bar code should follow this format:
Code:
<code>For Each ws In Worksheets </code><code> ' some code here
wsi = ws.Index ' Capture index to worksheet
' some more code here
For r = 1 To RowMax
For c = 1 To ColMax
' even more code here
PctDone = (RowMax * ColMax * wsi-1 + r * c)/ (RowMax * ColMax * Worksheets.Count)
Next c
' yet more code here
Next r
' and finally code here
Next ws
However I don't know how to integrate this into the below code so that it works:
Code:
Private Sub CommandButton1_Click()
Dim Firstrow As Long
Dim Lastrow As Long
Dim MyFile1 As Variant
Dim ActualDate As Date
MyFile1 = Application.GetOpenFilename
If MyFile1 = False Then Exit Sub
Workbooks.Open Filename:=MyFile1
ActiveWindow.View = xlNormalView
Range("A1").Select
Dim CostsTo As String
UserForm1.Hide
Do
Cells.Find(What:="Project Details", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Firstrow = ActiveCell.Row()
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Lastrow = ActiveCell.Row()
Rows(Firstrow & ":" & Lastrow).Select
Selection.Cut
Sheets.Add After:=Sheets(Sheets.Count)
Range("A3").Select
ActiveSheet.Paste
Worksheets(1).Activate
Range("A1").Select
On Error GoTo Errorhandler1
Loop
Errorhandler1:
Worksheets(1).Activate
Range("A1").Select
Dim Title As String
Title = ActiveCell
''''msgbox Title
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
Cells.Select
Range("A1").Activate
Selection.ColumnWidth = 15
Range("A1").Select
'deletes project end date
Cells.Find(What:="Project End Date", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Application.CutCopyMode = False
Selection.ClearContents
ActiveCell.Offset(0, 1).Activate
Selection.ClearContents
ActiveCell.Offset(1, 0).Activate
Selection.ClearContents
ActiveCell.Offset(0, -1).Activate
Selection.ClearContents
'Moves % spend
Range("D7:D8").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("E7:E8").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("D7").Select
Selection.FillDown
Range("E7").Select
Selection.FillDown
'adds budget spend %
Range("D6").Select
ActiveCell = "% Budget Spent"
Range("E14").Select
SpentPCent = ActiveCell
Range("E6").Select
Selection.NumberFormat = "0.00"
ActiveCell = SpentPCent
Range("D7").Select
ActiveCell = "% Time Elapsed"
Range("E9").Select
TimeElap = ActiveCell
Range("E7").Select
Selection.NumberFormat = "0.00"
ActiveCell = TimeElap
Range("D9").Select
Selection.ClearContents
ActiveCell.Offset(0, 1).Activate
Selection.ClearContents
Range("D8").Select
ActiveCell = "Top Task Number"
Range("B12").Select
TopTask = ActiveCell
Range("E8").Select
ActiveCell = TopTask
'deletes task info box
Rows("10:16").Select
Selection.Delete Shift:=xlUp
Range("A10").Select
'''msgbox ""
Dim ProNum As String
Cells.Find(What:="Project Number", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Select
ProNum = ActiveCell
''''msgbox ProNum
'Roles up EC non Staff budgets and spend
' Cells.Find(What:="funder", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
' :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
' False, SearchFormat:=False).Activate
'ActiveCell.Offset(0, 1).Activate
'If ActiveCell = "European Commission" Then
' Cells.Find(What:="Expenditure Category", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
' :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
' False, SearchFormat:=False).Activate
'Do Until ActiveCell = "Top Task Total"
'ActiveCell.Offset(1, 0).Activate
'If ActiveCell <> "Other Direct Costs" Then '''msgbox "what next?"
'Loop
'End If
'deletes rows where budget and actuals are zero
Cells.Find(What:="Funds Available", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
''''msgbox ActiveCell
''''msgbox "stop"
Dim RemoveCell1
Dim RemoveCell2
Do Until ActiveCell.Offset(0, -4) = ""
RemoveCell1 = ActiveCell.Offset(0, -4)
RemoveCell2 = ActiveCell.Offset(0, -3)
If RemoveCell1 + RemoveCell2 = "0" Then Selection.EntireRow.Delete: ActiveCell.Offset(-1, 0).Select
ActiveCell.Offset(1, 0).Select
Loop
'adds subtotal
''''msgbox ""
Dim EndCell As String
Dim StartCell As String
Range("A1").Select
Cells.Find(What:="Task Cost Summary Report", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
''''msgbox ""
ActiveCell.Offset(1, 0).Activate
StartCell = ActiveCell.Row()
Cells.Find(What:="Funds Available", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.End(xlDown).Select
''''msgbox ""
EndCell = ActiveCell.Row()
''''msgbox ""
Range("B" & StartCell & ":H" & EndCell - 1).Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(3, 4, 5, 6, _
7), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
''''msgbox ""
Range("A1").Select
Cells.Find(What:="Grand Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Rows(ActiveCell.Row).Select
Selection.Delete Shift:=xlUp
'''msgbox ""
'WAS HERE
'makes subtotal bold
''msgbox "sub bold"
Range("A1").Select
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
''''msgbox ""
EndCell = ActiveCell.Row()
''msgbox StartCell
With Range("B" & StartCell & ":H" & EndCell + 1)
''msgbox EndCell
Set C = .Find(What:="subtotal", LookIn:=xlFormulas)
If Not C Is Nothing Then
firstAddress = C.Address
Do
C.EntireRow.Font.Bold = True
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <> firstAddress
End If
End With
''''msgbox ""
'adds %spent
Range("A1").Select
Cells.Find(What:="Funds Available", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "% Spent"
ActiveCell.Offset(0, -1).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A1").Select
'Cells.Find(What:="All Total", After:=ActiveCell, LookIn:=xlFormulas, _
'LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
'MatchCase:=False, SearchFormat:=False).Activate
'ActiveCell.Offset(0, 6).Select
'Selection.Copy
'ActiveCell.Offset(0, 1).Select
'Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
' SkipBlanks:=False, Transpose:=False
Columns("I:I").Select
Selection.NumberFormat = "0.00%"
Selection.NumberFormat = "0%"
Range("A1").Select
Cells.Find(What:="% Spent", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Offset(0, -5) = ""
''''msgbox "Pause"
Dim Bnumber As Integer
Bnumber = 1
On Error Resume Next
''''msgbox Err.Number
If ActiveCell.Offset(0, -7) <> " " Or ActiveCell.Offset(0, -4) <> "0" Or ActiveCell.Offset(0, -5) <> "0" Then
'If Err.Number > 0 Then
''''msgbox Err.Number
On Error Resume Next
If ActiveCell.Offset(0, -5) = 0 Then
ActiveCell = ActiveCell.Offset(0, -2) / Bnumber
Else:
ActiveCell = ActiveCell.Offset(0, -2) / ActiveCell.Offset(0, -5)
End If
End If
On Error GoTo 0
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Selection.Font.Bold = True
'inserts message about no budget
''''msgbox "stop"
Cells.Find(What:="% Spent", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Offset(0, -5) = ""
If ActiveCell.Value = "" Then ActiveCell.Value = "No Budget"
ActiveCell.Offset(1, 0).Select
Loop
Columns("I:I").EntireColumn.AutoFit
Cells.Find(What:="% Spent", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Select
ActiveCell = "Balance Remaining"
Columns("H:H").EntireColumn.AutoFit
'hides RC savings lines and leaves total
'Dim RCHide As String
'Dim RCunhide As String
'RCHide = "RC RCUK Efficiency Savings"
'RCunhide = "RC RCUK Efficiency Savings Total"
Range("B1").Select
Cells.Find(What:="Task Name", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Value = "Top Task Total"
If ActiveCell.Value = "RCUK" Then Selection.EntireRow.Hidden = True
'If ActiveCell.Value = RCunhide Then Selection.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
''''msgbox "stop"
'deletes summary
ActiveCell.Offset(1, 0).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).EntireRow.Delete
Range("I12").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Columns("I:I").EntireColumn.AutoFit
Columns("F:F").EntireColumn.AutoFit
Columns("G:G").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("I11").Select
Range(Selection, Selection.End(xlToLeft)).Select
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Range("A11:I11").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
' Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.748031496062992)
.RightMargin = Application.InchesToPoints(0.748031496062992)
.TopMargin = Application.InchesToPoints(0.984251968503937)
.BottomMargin = Application.InchesToPoints(0.984251968503937)
.HeaderMargin = Application.InchesToPoints(0.511811023622047)
.FooterMargin = Application.InchesToPoints(0.511811023622047)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
' Application.PrintCommunication = True
Range("A1").Select
''''msgbox "Tidy"
Rows("3:3").Select
Selection.UnMerge
Range("C4:C9").Select
Selection.UnMerge
Rows("9:12").Select
''''msgbox ""
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D4:E9").Select
Selection.Copy
Range("A9").Select
ActiveSheet.Paste
' Rows("9:9").Select
' Application.CutCopyMode = False
' Selection.Delete Shift:=xlUp
'Rows("14:14").Select
'Selection.Delete Shift:=xlUp
Rows("3:3").Select
Selection.UnMerge
Range("C3:E14").Select
Selection.ClearContents
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("A3:B13").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("A1").Select
' Selection.Delete Shift:=xlUp
Range("B4:B13").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Dim SpendPercent As String
Dim TimePercent As String
Range("B11").Select
ActiveCell.Value = Round(ActiveCell.Value, 0)
Range("B12").Select
ActiveCell.Value = Round(ActiveCell.Value, 0)
Range("B11:B12").Select
Selection.NumberFormat = "0"
Range("B11").Select
SpendPercent = ActiveCell
''''msgbox SpendPercent
Selection.NumberFormat = "@"
ActiveCell = SpendPercent & "%"
Range("B12").Select
TimePercent = ActiveCell
' '''msgbox SpendPercent
Selection.NumberFormat = "@"
ActiveCell = TimePercent & "%"
'Round.ActiveCell
Range("A14:B14").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("A3:B13").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("A15:I15").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("A15:I15").Select
Selection.UnMerge
Columns("D:H").Select
Selection.NumberFormat = "#,##0.00_ ;[Red]-#,##0.00 "
Range("A15:I15").Select
Selection.Merge
Range("A1").Select
'adds formulas to report
Cells.Find(What:="Total Cost", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Do Until ActiveCell = ""
If Selection.Font.Bold = False Then
ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"
ActiveCell.Offset(1, 0).Activate
Else: ActiveCell.Offset(1, 0).Activate
End If
Loop
Cells.Find(What:="Balance Remaining", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Do Until ActiveCell = ""
If Selection.Font.Bold = False Then
ActiveCell.FormulaR1C1 = "=RC[-4]-RC[-1]"
ActiveCell.Offset(1, 0).Activate
Else: ActiveCell.Offset(1, 0).Activate
End If
Loop
Cells.Find(What:="% Spent", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Do Until ActiveCell = ""
If ActiveCell.Value = "No Budget" Then
ActiveCell.Offset(1, 0).Activate
Else: ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-5]"
ActiveCell.Offset(1, 0).Activate
End If
Loop
'inserts message about no budget
''''msgbox "stop"
Dim cel As Range
Cells.Find(What:="% Spent", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Offset(0, -5) = ""
If ActiveCell.Offset(0, -5) = "0" Then ActiveCell = "No Budget"
ActiveCell.Offset(1, 0).Select
Loop
'subtotals bottom line
Cells.Find(What:="Total Budget", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Dim Start As String
Dim Finish As String
Dim LineNos As String
Start = ActiveCell.Row()
''''msgbox Finish - Start
Selection.End(xlDown).Select
ActiveCell.Offset(-1, 0).Activate
Finish = ActiveCell.Row()
'''msgbox Finish
LineNos = Finish - Start + 1
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & LineNos & "]C:R[-1]C)"
''''msgbox ""
Cells.Find(What:="Actuals", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Start = ActiveCell.Row()
''''msgbox Start
Selection.End(xlDown).Select
ActiveCell.Offset(-1, 0).Activate
Finish = ActiveCell.Row()
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & LineNos & "]C:R[-1]C)"
Range("A1").Select
Cells.Find(What:="Commitments", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Start = ActiveCell.Row()
''''msgbox Start
Selection.End(xlDown).Select
ActiveCell.Offset(-1, 0).Activate
Finish = ActiveCell.Row()
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & LineNos & "]C:R[-1]C)"
Cells.Find(What:="Total Cost", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Start = ActiveCell.Row()
''''msgbox Start
Selection.End(xlDown).Select
ActiveCell.Offset(-1, 0).Activate
Finish = ActiveCell.Row()
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & LineNos & "]C:R[-1]C)"
Cells.Find(What:="Balance Remaining", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Activate
Start = ActiveCell.Row()
''''msgbox Start
Selection.End(xlDown).Select
ActiveCell.Offset(-1, 0).Activate
Finish = ActiveCell.Row()
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & LineNos & "]C:R[-1]C)"
ActiveWindow.View = xlNormalView
Range("A1").Select
ActiveCell = Title
ActiveCell.Font.Bold = True
Cells.Select
Selection.RowHeight = 15
Range("A1").Select
Cells.Find(What:="Task Name", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Offset(0, -1).Value = "Top Task Total"
If ActiveCell.Value = "RCUK" Then Selection.EntireRow.Hidden = True
'If ActiveCell.Value = RCunhide Then Selection.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
'Columns("I:I").EntireColumn.AutoFit
'HERE
'Columns("B:I").EntireColumn.AutoFit
ActiveSheet.Name = ProNum
Rows("13:13").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A13").Select
ActiveCell.FormulaR1C1 = "Actuals As At"
ActiveCell.Offset(0, 1).Value = DTPicker1
Range("B13").Select
Selection.ClearContents
Selection.NumberFormat = "dd-mmm-yy"
ActiveCell.FormulaR1C1 = "=TODAY()"
Range("A1").Select
'adds Notes relating to end date
Cells.Find(What:="announced end", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Select
ActiveCell.Name = "ABC"
Cells.Find(What:="actuals as at", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Select
ActiveCell.Name = "DEF"
Range("ABC").Select
'less than 6 months
If (Range("ABC") - Range("DEF") < 183 And (Range("ABC") - Range("DEF") >= 91)) Then
ActiveCell.Interior.ColorIndex = 6 ' Color cell interior yellow
ActiveCell.Offset(-3, 2).Activate
ActiveCell.Value = "This project is due to end within the next 6 months."
ActiveCell.Name = "GHI"
ActiveCell.Offset(-1, 0).Activate
ActiveCell.Value = "Note:"
ActiveCell.Name = "JKL"
Union(Range("GHI"), Range("JKL")).Select
With Selection
.WrapText = False
.Font.Italic = True
.Font.Bold = True
End With
'less than 3 months
ElseIf (Range("ABC") - Range("DEF") <= 90 And (Range("ABC") - Range("DEF") >= 61)) Then
ActiveCell.Interior.ColorIndex = 44 'Color cell darker yellow/gold
ActiveCell.Offset(-3, 2).Activate
ActiveCell.Value = "This project is due to end within the next 3 months."
ActiveCell.Name = "GHI"
ActiveCell.Offset(-1, 0).Activate
ActiveCell.Value = "Note:"
ActiveCell.Name = "JKL"
Union(Range("GHI"), Range("JKL")).Select
With Selection
.WrapText = False
.Font.Italic = True
.Font.Bold = True
End With
'Less than 2 months
ElseIf (Range("ABC") - Range("DEF") <= 60 And (Range("ABC") - Range("DEF") >= 31)) Then
ActiveCell.Interior.ColorIndex = 45 'Cell color even darker yellow/light orange
ActiveCell.Offset(-3, 2).Activate
ActiveCell.Value = "This project is due to end within the next 2 months."
ActiveCell.Name = "GHI"
ActiveCell.Offset(-1, 0).Activate
ActiveCell.Value = "Note:"
ActiveCell.Name = "JKL"
Union(Range("GHI"), Range("JKL")).Select
With Selection
.WrapText = False
.Font.Italic = True
.Font.Bold = True
End With
'Less than one month
ElseIf (Range("ABC") - Range("DEF") <= 30 And (Range("ABC") - Range("DEF") >= 1)) Then
ActiveCell.Interior.ColorIndex = 46 'Cell color darkest orange
ActiveCell.Offset(-3, 2).Activate
ActiveCell.Value = "This project is due to end within the next month."
ActiveCell.Name = "GHI"
ActiveCell.Offset(-1, 0).Activate
ActiveCell.Value = "Note:"
ActiveCell.Name = "JKL"
Union(Range("GHI"), Range("JKL")).Select
With Selection
.WrapText = False
.Font.Italic = True
.Font.Bold = True
End With
'finished
ElseIf Range("ABC") - Range("DEF") <= 0 Then
ActiveCell.Interior.ColorIndex = 3 ' Color cell darkest red
ActiveCell.Offset(-3, 2).Activate
ActiveCell.Value = "This project has now finished."
ActiveCell.Name = "GHI"
ActiveCell.Offset(-1, 0).Activate
ActiveCell.Value = "Note:"
ActiveCell.Name = "JKL"
Union(Range("GHI"), Range("JKL")).Select
With Selection
.WrapText = False
.Font.Italic = True
.Font.Bold = True
End With
Else
ActiveCell.Select
End If
Range("A1").Select
ActiveSheet.Name = ProNum
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'deletes summary
ActiveCell.Offset(1, 0).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).EntireRow.Delete
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(2, 0).Select
ActiveCell = "1. Salary commitments, as held on the HR or Payroll systems, are not included in this report."
Dim RowLocation As Long 'can hold over 32000 if over this many rows
Dim ColumnLocation As Integer 'columns won't exceed 256 in sheet
Dim CellLocation As String
Range("B1").Select
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 7).Select
CellLocation = ActiveCell.Address
''msgbox CellLocation
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(3, 0).Select
ActiveCell = "Please bear this in mind when reviewing the remaining balance total of:"
Dim CurrentCell As String
CurrentCell = ActiveCell.Row()
Range("A" & CurrentCell & ":D" & CurrentCell).Merge
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = "=" & CellLocation
Selection.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
''msgbox "OK?"
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(4, 0).Select
ActiveCell = "2. Commitments - Costs that have been charged to the award, but are not yet actual e.g. a PO that has yet to be matched to an invoice."
Cells.Find(What:="Top Task Total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(5, 0).Select
ActiveCell = "3. %Time Elapsed = Number of days since the start date of the award as a percentage of the duration of the award."
'msgbox "stop"
Columns("C:C").Select
Selection.ColumnWidth = 20
Columns("E:E").Select
Selection.ColumnWidth = 12
Next ws
'Application.ScreenUpdating = True
' ActiveWindow.Close
'End If
End Sub
Thanks.
</code>