Results 1 to 5 of 5

Thread: Activity Based Depreciation If /Then VBA Code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    14
    I know that this post was not written well enough. I have reevaluated the process that needs to take place and believe that I have figured out a logical way to go about this process. I have posted a more detailed and well thought out notion of this process at: Link to Forum

    Thank you for all who attempted this process. I am still working on it and if a solution arises I will post it here for your reference!!
    Using Excel 2010

  2. #2
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    14
    I ended up making a user form for the depreciation schedule. This is the code I used to complete the automation:
    Code:
    Private Sub UserForm_Initialize()
       TextBox1.Value = ""
       TextBox2.Value = ""
       TextBox3.Value = ""
       TextBox4.Value = ""
       TextBox5.Value = ""
       TextBox1.SetFocus
       End Sub
    Private Sub CommandButton2_Click()
    Unload Me
    End Sub
    Private Sub EnterData_Click()
    Dim ws As Worksheet
       Set ws = Worksheets("Depreciation")
    
       'Insert Total Hours
       ws.Cells(14, 4).Value = TextBox1.Value
       ws.Cells(15, 4).Value = TextBox1.Value
       ws.Cells(16, 4).Value = TextBox2.Value
       ws.Cells(17, 4).Value = TextBox3.Value
       ws.Cells(18, 4).Value = TextBox4.Value
       ws.Cells(19, 4).Value = TextBox5.Value
       'Insert Year Headers
       ws.Cells(14, 3).Formula = "=IF(D14="""", """", ""Year 1"")"
       ws.Cells(15, 3).Formula = "=IF(D15="""", """", ""Year 1"")"
       ws.Cells(16, 3).Formula = "=IF(D16="""", """", ""Year 2"")"
       ws.Cells(17, 3).Formula = "=IF(D17="""", """", ""Year 3"")"
       ws.Cells(18, 3).Formula = "=IF(D18="""", """", ""Year 4"")"
       ws.Cells(19, 3).Formula = "=IF(D18="""", """", ""Year 5"")"
       'Insert Hourly Rate
       ws.Cells(14, 5).Formula = "=$D$10"
       ws.Cells(15, 5).Formula = "=$D$10"
       ws.Cells(16, 5).Formula = "=$D$10"
       ws.Cells(17, 5).Formula = "=$D$10"
       ws.Cells(18, 5).Formula = "=$D$10"
       ws.Cells(19, 5).Formula = "=$D$10"
       'Insert Depreciation Rate
       ws.Cells(14, 6).Formula = "=D14*E14"
       ws.Cells(15, 6).Formula = "=D15*E15"
       ws.Cells(16, 6).Formula = "=D16*E16"
       ws.Cells(17, 6).Formula = "=D17*E17"
       ws.Cells(18, 6).Formula = "=D18*E18"
       ws.Cells(19, 6).Formula = "=D19*E19"
       'Insert Accumulated Depreciation
       ws.Cells(14, 7).Formula = "=F14"
       ws.Cells(15, 7).Formula = "=F14"
       ws.Cells(16, 7).Formula = "=G15+F16"
       ws.Cells(17, 7).Formula = "=G16+F17"
       ws.Cells(18, 7).Formula = "=G17+F18"
       ws.Cells(19, 7).Formula = "=G18+F19"
       'New Value
       ws.Cells(14, 8).Formula = "=$D$5-F14"
       ws.Cells(15, 8).Formula = "=$D$5-F15"
       ws.Cells(16, 8).Formula = "=H15-F16"
       ws.Cells(17, 8).Formula = "=H16-F17"
       ws.Cells(18, 8).Formula = "=H17-F18"
       ws.Cells(19, 8).Formula = "=H18-F19"
       Call AutomateDepreciationExpense
       Call AutomateDepreciationExpense1
       Range("B2").Select
       Unload UserForm1
    End Sub
    Sub AutomateDepreciationExpense()
    Dim x As Integer
    For x = 15 To 19
    If Cells(x, 7).Value > Cells(9, 4).Value Then
    Cells(x, 6).Formula = "=" & Cells(9, 4).Address(0, 0) & "-" & Cells(x - 1, 7).Address(0, 0)
    Range(Cells(x + 1, 3), Cells(20, 8)).ClearContents
    Else
    End If
    Next
    End Sub
    
    Sub AutomateDepreciationExpense1()
    Dim x As Integer
    For x = 14 To 15
    If Cells(x, 4).Value > Cells(7, 4).Value Then
    Cells(x, 6).Formula = "=D9"
    Else
    End If
    Next
    End Sub
    Using Excel 2010

Similar Threads

  1. Projected Depreciation in Excel
    By Suhail in forum Excel Help
    Replies: 7
    Last Post: 01-04-2014, 01:51 AM
  2. Replies: 17
    Last Post: 05-22-2013, 11:58 PM
  3. VBA and Depreciation
    By Whitley in forum Excel Help
    Replies: 0
    Last Post: 03-16-2013, 01:32 AM
  4. How to track user activity using a macro?
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 08-10-2012, 06:50 PM
  5. Visual Plotter basis given dates and activity
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 2
    Last Post: 03-07-2012, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •