Simple Macro


Posted by Rick Baldonieri on January 25, 2000 7:08 PM

First I come from a 1-2-3 DOS environment so I need plenty of help. I need to create a macro that will allow data entry(numbers)into a cell and by pressing the "Enter" key have the entry point move to a new cell location and wait for new data to be entered. The direction and distance of movement will "vary". Example:Imput a number in A1,press "Enter" key moving to cell A2, stopping to allow another number imput,press "Enter" key moving to cell B1 and continue on. Once all data is entered and calculations are recorded I need to erase the data entered and begin anew. Thanks in advance!



Posted by Chris on January 26, 2000 5:32 AM

Rick,

This should get you started:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 2 Then Cells(1, Target.Column + 1).Select
End Sub

This is known as an event procedure. When a change is made to the spreadsheet, this macro runs automatically. What you then do is check the location of the change (Target.Address) to see if you need to move the cursor somewhere else, or run another macro.

This procedure goes in the code for the sheet, not a module.

My example says that if the target row is 2, then go to row 1 in the next column.

Good Luck,

Chris