Populating table with VBA

pholt33

Board Regular
Joined
Jan 4, 2005
Messages
202
Office Version
  1. 365
Platform
  1. Windows
I am working on a file to show the impact of investing in multiple properties over time. I have the base all set and would like a way to update additional fields based on input box, for example (in words) "buy 1 additional property every 2 years for 10 years."
In the screenshot, it would populate whole numbers in J4:J22 like in the table on the right. D4 is a whole number.

I can do it with formulas (2nd screenshot) but I want the flexibility to also manually input in J4:J22.

How can I do this with VBA?

Thanks!
 

Attachments

  • NewInvestments.jpg
    NewInvestments.jpg
    76 KB · Views: 6
  • NewInvestmentsFormula.jpg
    NewInvestmentsFormula.jpg
    55 KB · Views: 6

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Got it figured out by modifying some other code I found.



VBA Code:
 Sub InputBoxYears()

    Dim YearInterval As Double
    Dim YearNumber As Double
   
    Application.ScreenUpdating = False
   
    YearInterval = Application.InputBox(prompt:="Every X years", Title:="Input year interval", Type:=1)
    YearNumber = Application.InputBox(prompt:="For Y years", Title:="Input number of years", Type:=1)
   
    Range("SecondPurchase") = Range("FirstPurchase") + YearInterval
 
     For Each Cell In Range("Years3to20")
        If Cell.Value <= (YearNumber / YearInterval) Then
            Cell.Offset(0, 1).Value = Cell.Offset(-1, 1).Value + YearInterval
        End If
    Next Cell

 End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top