Create Data List with Variable Number of Cells

TheDenouement

New Member
Joined
Aug 24, 2010
Messages
10
Is there a way to create some kind of output into multiple cells?

For instance, I have a dollar amount that I want to increase by 5% each year but I don't know how many years yet. But based on user input (say 10yrs) 10 cells would be created, each 5% larger than the next?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Copy this code into the Object of the sheet you need this in.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim x As Variant

For x = 0 To 9
    If Not Intersect(Target, Range("B3")) Is Nothing Then
        If x = 0 Then
            Range("B5").Value = Target.Value * 1.05
        Else
            Range("B5").Offset(x, 0).Value = Range("B5").Offset(x - 1, 0).Value * 1.05
        End If
    End If
Next x

End Sub

When entering a value in cell B3 a list will be created in the cells B5:B14

Success

Erik
 
Upvote 0
Great! I am very slowly learning to understand enough VBA to manipulate it. VERY slowly.

What type of code would I use to have it clear the data and replace it whenever new input is typed?

Do I need special code to have text automatically generated into adjacent cells to annotate the results?

Thanks for all the help!
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim x As Variant
Dim i As Variant

i = Cells(Cells.Rows.Count,"B").End(xlUp).Row
Range("B5:B" & i).ClearContents

For x = 0 To 9
    If Not Intersect(Target, Range("B3")) Is Nothing Then
        If x = 0 Then
            Range("B5").Value = Target.Value * 1.05
            Range("B5").Offset(0,1).Value = "Text" & 0
        Else
            Range("B5").Offset(x, 0).Value = Range("B5").Offset(x - 1, 0).Value * 1.05
            Range("B5").Offset(x, 1).Value = "Text" & x
        End If
    End If
Next x

End Sub

Be aware that all data from cell B5 till the last value in column B will be cleared.
 
Upvote 0

Forum statistics

Threads
1,215,968
Messages
6,127,983
Members
449,414
Latest member
sameri

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