+ Reply to Thread
Results 1 to 5 of 5

enter 4 colums of data in a row then shift after hitting enter

  1. #1
    Registered User
    Join Date
    05-31-2014
    Location
    New Zealand
    Posts
    31

    enter 4 colums of data in a row then shift after hitting enter

    Hi,
    I really know nothing about vba so here goes. I would like to enter data in a row with 4 cells of info. then hit enter and return to the first cell and move the row down. all four cells must have data entered. and all four must move down. i tried some code as below i found and i modified but it did not work as expected. this moved the row down when returning the cursor to A2. It also should not copy the data style of the top row. Whats the best way to do this ?? Any help would be appreciated.

    cheers Mark



    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column <> 1 Then Exit Sub
    Application.EnableEvents = False
    If [E2] <> "" Then
    [E2].Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    [E2].Select
    End If

    Application.EnableEvents = True

    If Target.Column <> 1 Then Exit Sub
    Application.EnableEvents = False
    If [D2] <> "" Then
    [D2].Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    [D2].Select
    End If

    Application.EnableEvents = True

    If Target.Column <> 1 Then Exit Sub
    Application.EnableEvents = False
    If [C2] <> "" Then
    [C2].Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    [C2].Select
    End If

    Application.EnableEvents = True

    If Target.Column <> 1 Then Exit Sub
    Application.EnableEvents = False
    If [B2] <> "" Then
    [B2].Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    [B2].Select
    End If
    Application.EnableEvents = True

    If Target.Column <> 1 Then Exit Sub
    Application.EnableEvents = False
    If [A2] <> "" Then
    [A2].Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    [A2].Select
    End If
    Application.EnableEvents = True
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: enter 4 colums of data in a row then shift after hitting enter

    Hi, Mark,

    welcome to ExcelForum. Please mind that you should wrap your procedure with code-tags according to Forum Rule #3 in order for us to answer our quewstion.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    05-31-2014
    Location
    New Zealand
    Posts
    31

    Re: enter 4 colums of data in a row then shift after hitting enter

    Hi,
    I really know nothing about vba so here goes. I would like to enter data in a row with 4 cells of info. then hit enter and return to the first cell and move the row down. all four cells must have data entered. and all four must move down. i tried some code as below i found and i modified but it did not work as expected. this moved the row down when returning the cursor to A2. It also should not copy the data style of the top row. Whats the best way to do this ?? Any help would be appreciated. post corrected i think. cheers

    cheers Mark
    Please Login or Register  to view this content.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: enter 4 colums of data in a row then shift after hitting enter

    Hi, Mark,

    you could have edited the original post instead.

    all code goes behind the sheet. This will change the cursor movement to go right after each Enter when you activate the sheet and return to any other movement if you deactivate the sheet. The code will only get triggered once you reach Column E and have all cells in range A2:D2 filled:

    Please Login or Register  to view this content.
    There may only be one event with the name of Worksheet_SelectionChange behind a sheet so you would to delete or comment any other code out in order to make the code run.

    If there is only one sheet in the workbook you would need to use different events in ThisWorkbook in order to get the cursor movement working as expected.

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    05-31-2014
    Location
    New Zealand
    Posts
    31

    Re: enter 4 colums of data in a row then shift after hitting enter

    Hi Holger, Thank you for posting the code, i had a look to see if i could edit original post, But it wasnt obvious at the time. It works well though.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. With VBA Enter Ctrl Shift Enter For Array Formula
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-17-2013, 09:02 AM
  2. Replies: 5
    Last Post: 12-06-2010, 04:39 PM
  3. [SOLVED] What does Ctrl+Shift+Enter do? How does it differ from Enter?
    By George Furnell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2006, 02:45 AM
  4. Replies: 2
    Last Post: 10-20-2005, 05:05 PM
  5. ctrl+shift+enter vs enter
    By tkaplan in forum Excel General
    Replies: 7
    Last Post: 05-27-2005, 12:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1