RDA Midwest
New Member
- Joined
- Oct 3, 2012
- Messages
- 12
Ok... so here's a macro I wrote for an Excel spreadsheet we've been using for a few years.
I love the efficiency of it. What used to take us 1 to 1.5 hours is now done in about 5 seconds.
A little more than 10 years ago I messed around with basic a lot, and recently started diggin into VBA for this purpose.
Just wondering if anyone can give me any feedback.... if there's anything that's obviously 'messed up' or could be done 'better'
Keep in mind that some of this is written in a way to be compatible as far back as Excel 2003, though, in our office, we mainly work in 2010.
I love the efficiency of it. What used to take us 1 to 1.5 hours is now done in about 5 seconds.
A little more than 10 years ago I messed around with basic a lot, and recently started diggin into VBA for this purpose.
Just wondering if anyone can give me any feedback.... if there's anything that's obviously 'messed up' or could be done 'better'
Keep in mind that some of this is written in a way to be compatible as far back as Excel 2003, though, in our office, we mainly work in 2010.
Code:
Private Sub CommandButton1_Click()
'Copyright 2010-2013 Reserve Data Analysis, Inc. (Minneapolis, MN)
'Paste Form Values
Range("o615") = Val(TextBox2)
Range("l624") = Val(TextBox3) & "%"
Range("l625") = Val(TextBox4) & "%"
Range("n624") = Val(TextBox5) & "%"
Range("j628") = Val(TextBox6)
Range("n620") = Val(TextBox7)
Range("as632") = Val(TextBox8)
Range("as627") = Val(TextBox9)
'Beginning Accrued Depreciation
Range("as631") = "Accrued Depreciation " & TextBox10.Value & "/" & (TextBox2.Value)
Range("as633") = "Depreciation Funded " & TextBox10.Value & "/" & (TextBox2.Value)
'End Accrued Depreciation
Range("as626") = "Accrued Depreciation " & TextBox11.Value & "/" & (TextBox2.Value + 29)
Range("as628") = "Depreciation Funded " & TextBox11.Value & "/" & (TextBox2.Value + 29)
'Open and delimit SPREAD.TXT ASCII EXPORT FROM RDA SOFTWARE
Workbooks.OpenText Filename:="C:\Reserve\SPREAD.TXT", Origin:=65000, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True, _
Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array( _
3, 1)), TrailingMinusNumbers:=True
'Copy and paste Beginning Reserve Balance
Range("G7").Select
Selection.Copy
Windows("RDA Midwest DCF TEMPLATE 600.xlsm").Activate
Range("O616").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy and paste Association Name
Windows("SPREAD.TXT").Activate
Range("A1").Select
Selection.Copy
Windows("RDA Midwest DCF TEMPLATE 600.xlsm").Activate
Range("I1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy & Paste Headings and Financials from SPREAD.TXT
Windows("SPREAD.TXT").Activate
Range("A17:AJ608").Select
Selection.Copy
Windows("RDA Midwest DCF TEMPLATE 600.xlsm").Activate
Range("I6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy and Paste Dates from Funding Rows to avoid discrepancy
Range("O615:AR615").Select
Selection.Copy
Range("O7").Select
ActiveSheet.Paste
'Generate Summary Info
Range("I2") = "DCF Directed Cash Flow Modeling Example"
Range("I3") = "Report Date: " & Date
Range("I4") = "Version Basis: " & TextBox1
Range("I5") = "Cost Inflation: " & TextBox4 & "%"
Range("I6") = "EXPENDITURE DETAIL"
'Fiscal Year Beginning, At Funding Rows
Range("k615") = "Fiscal Year Beginning: " & TextBox10.Value & "/" & TextBox2.Value
'Chart Title String
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 532.5, _
-8.25, 72, 72).Select
Selection.ShapeRange.ScaleWidth 14#, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 5#, msoFalse, msoScaleFromTopLeft
Selection.Characters.Text = Range("i1") & vbCrLf & _
"Reserve Analysis for Fiscal " & TextBox2.Value & vbCrLf & _
"Directed Cash Flow (DCF) Modeling Example" & vbCrLf & _
"Depreciation Funded " & TextBox11.Value & "/" & (TextBox2.Value + 29) & ": " & vbCrLf & _
"Depreciation Funded " & TextBox10.Value & "/" & TextBox2.Value & ": " & Range("as634").Text
Selection.Font.Bold = msoTrue
Selection.Font.Size = 48
Selection.Font.Name = "Calibri"
'Make textbox for ending accrued depreciation and assign formula to reference cell
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 1240.8750393701, _
180.8750393701, 209, 58.5).Select
Selection.Formula = "=DCF!$AS$629"
Selection.Font.Bold = msoTrue
Selection.Font.Size = 48
Selection.Font.Name = "Calibri"
'Select component description column range, delete unused rows
Range("I8:I608").Select
Range("I608").Activate
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'Close SPREAD.TXT
Windows("SPREAD.TXT").Activate
ActiveWorkbook.Close
'Close UserForm
UserForm1.Hide
'Select Top
Range("i1").Select
'Finishing MessageBox & Save As Prompt w/ Name Assignment
MsgBox "The Macro has completed. You will now be prompted to SAVE-AS" & vbCrLf & _
"The WorkSheet will automatically be assigned the following Name:" & vbCrLf & vbCrLf & _
"DCF Directed Cash Flow Modeling Example " & TextBox1.Value & " for " & Range("I1").Value & " " & TextBox2.Value & vbCrLf & vbCrLf & _
"You may change the name and format as you wish: .XLS recommended for broadest end user compatibility" & vbCrLf & vbCrLf & _
"Macro Courtesy of Reserve Data Analysis, Inc. Minneapolis MN" & vbCrLf & _
"http://www.RDAmidwest.com , MPLS 612.616.4817" & vbCrLf & _
"Written by: Jonathan R. Pettersen, RS #174", vbInformation + vbOKOnly
Application.Dialogs(xlDialogSaveAs).Show "DCF Directed Cash Flow Modeling Example " & TextBox1.Value & " for " & Range("I1").Value & " " & TextBox2.Value
'Done. Smile. Have a nice day :)
End Sub