Excel- Generate a list from single cell input

microsoft excelworksheet-function

My question is basically how can you generate a list in Excel based on a single cell input?

For example, the user types 10 then replaces it with 20 and then 30 etc, is it possible to generate a list like:
10
20
30
etc

EDIT: As an additional requirement, is it possible it adjust the code, or provide an additional code to allow additional instances of this? For example, generate an additional list for a 2nd or 3rd etc single cell input.

Thanks for the help!
Alistair

Best Answer

This example monitors user changes to cell A1
The list is built in column B starting in cell B2

Put the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim RR As Range, N As Long, v As Variant
    Set RR = Intersect(Target, Range("A1"))
    If RR Is Nothing Then Exit Sub
    v = Range("A1").Text
    N = Cells(Rows.Count, "B").End(xlUp).Row + 1
    Application.EnableEvents = False
        Range("B" & N).Value = v
    Application.EnableEvents = True
End Sub

Because it is worksheet code, it is very easy to install and automatic to use:

  1. right-click the tab name near the bottom of the Excel window
  2. select View Code - this brings up a VBE window
  3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx

To remove the macro:

  1. bring up the VBE windows as above
  2. clear the code out
  3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

Macros must be enabled for this to work!

Related Question