Creating a directional macro [Solved/Closed]

Report
-
 Teene12 -
Hello,
I am not familiar with writing macros at all. I created a form and I need a macro so that when I input data in a cell the cursor will automatically go to the next required empty cell. So, basically I need the user of the form
to be able to enter data in a cell and when they press enter the cursor will automatically go to the next required cell. Please help.

6 replies

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
767
Oh I am sorry. When you said form, I presumed you meant the excel form. It seem that you are only using sheets and not the forms (excel forms). In this case have you considered using some thing like this

This code you can write in the sheet that you are using

If you press ALT+F11, a vbe will open up
Once it opens, press CTRL + R to open project explorer window (in case it is not open already)
Expand the tree "VBAProkect(...xls) -- Microsoft Excel Objects -- then double click on the sheet where you want that functionality
Paste the code and modify as you need

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

Add = Target.Address

' here you have to define how you want to move. in this sample,
' if a1 changes, i want to move to c3
' if c3 changes i want to move to d2

Select Case Add
Case "$A1$1"
Range("C3").Select

Case "$C$3"
Range("D2").Select

End Select

Application.EnableEvents = True


End Sub
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

Posts
1
Registration date
Monday February 1, 2010
Status
Member
Last seen
February 3, 2010

Ok, I did exactly what you said above. I copied and pasted the code and changed the cells that apply to my worksheet, but it does not work. What am I doing wrong? This is a foreign language to me, I have no clue. Am I supposed to activate it somehow? I don't have a password to access the EJHTML4E to show you a screen shot, otherwise I would.
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
767
This you should be able to do with the tab order. If you look at the properties of the textbox on your form, you will see an tabindex. It goes from 0 onward. You can have index set up the way you want the control to move
I'm sorry, I am not understanding what you mean. I created this in Excel, all the info. is created in cells, so I am not sure where to find the textbox properties.
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
767
mail it
Posts
7098
Registration date
Saturday April 7, 2007
Status
Moderator
Last seen
June 10, 2021
484
Hi,

To give an excel file example (without any personal data) you should use a deposit files website like https://authentification.site and after copy/paste the created link into your next answer.

Best regards
Thank you for your help, I figured it out. I just had to enable the macro when I closed the file and opened it back up again. it works perfect.

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!