Results 1 to 5 of 5

Thread: Activity Based Depreciation If /Then VBA Code

  1. #1
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    12

    Activity Based Depreciation If /Then VBA Code

    I am attaching a workbook that contains activity based depreciation formulas.
    I have written notes in it to explain the dilemma. I need to fill in a set of new values based on activity hours....
    I was thinking that the user could input estimated activity hours with a userform and then based on that would fill in the chart. Once the userform is submitted and the chart is completed I need to run a set of if/then statements behind the values to evaluate if they are greater then residual value. IF they are I need to plug in a value... Does anyone have any ideas on how to simplify this process?

    Any help and or suggestions/ideas would be much appreciated!

    -Matt
    Attached Files Attached Files
    Using Excel 2010

  2. #2
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    12
    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

  3. #3
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    12
    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

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Thanks mrmmickle for sharing this.

    For the Sub EnterData_Click, you could write it this way

    Code:
    Private Sub EnterData_Click()    
        Dim ws As Worksheet
        Set ws = Worksheets(2)
    
    
       'Insert Year Headers
       ws.Cells(14, 3).Resize(6).Formula = "=IF(D14="""", """", ""Year ""&ROW()-13)"
       
       'Insert Hourly Rate
       ws.Cells(14, 5).Resize(6).Formula = "=$D$10"
       
       'Insert Depreciation Rate
       ws.Cells(14, 6).Resize(6).Formula = "=D14*E14"
       
       'Insert Accumulated Depreciation
       ws.Cells(14, 7).Resize(2).Formula = "=$F$14"
       ws.Cells(16, 7).Resize(4).Formula = "=G15+F16"
       
       'New Value
       ws.Cells(14, 8).Resize(2).Formula = "=$D$5-F14"
       ws.Cells(16, 8).Resize(4).Formula = "=H15-F16"
       
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  5. #5
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    12
    ExcelFox,

    Thank you for the tip. I see how much easier this is and less typing!! I appreciate you following up on my post!
    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
  •