+ Reply to Thread
Results 1 to 5 of 5

Copy cells to neighbor column after leaving the cell

  1. #1
    nemadrias
    Guest

    Copy cells to neighbor column after leaving the cell

    Hi -
    Can anyone help me figure this out? I think I need a "With" loop, but
    haven't really worked with them yet.

    I have a column of empty cells. What I want to be able to do is copy
    whatever is typed in any of those cells to the cell immediately to the
    right of them in the column immediately to the right. I need to be
    able to do this in the event (leaveCell) or whatever the event would be
    called, basically as soon as the cursor leaves the cell (enter, tab,
    click, whatever....) Is there a good way to do this?? Thanks a ton!
    Steve


  2. #2
    Gord Dibben
    Guest

    Re: Copy cells to neighbor column after leaving the cell

    By formula...........

    In B1 enter =IF(A1="","",A1)

    Drag/copy down column B as far as you wish.

    Event code..................

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    'when entering data in a cell in Col A
    On Error GoTo enditall
    Application.EnableEvents = False
    If Target.Cells.Column = 1 Then
    n = Target.Row
    If Excel.Range("A" & n).Value <> "" Then
    Excel.Range("B" & n).Value = Excel.Range("A" & n).Value
    End If
    End If
    enditall:
    Application.EnableEvents = True
    End Sub

    Right-click on the sheet tab and "View Code".

    Copy/paste the code into that module.


    Gord Dibben MS Excel MVP

    On 11 Jul 2006 07:16:17 -0700, "nemadrias" <[email protected]> wrote:

    >Hi -
    >Can anyone help me figure this out? I think I need a "With" loop, but
    >haven't really worked with them yet.
    >
    >I have a column of empty cells. What I want to be able to do is copy
    >whatever is typed in any of those cells to the cell immediately to the
    >right of them in the column immediately to the right. I need to be
    >able to do this in the event (leaveCell) or whatever the event would be
    >called, basically as soon as the cursor leaves the cell (enter, tab,
    >click, whatever....) Is there a good way to do this?? Thanks a ton!
    >Steve



  3. #3
    nemadrias
    Guest

    Re: Copy cells to neighbor column after leaving the cell

    FANTASTIC!!! Thank you so much - the code is what I needed. Out of
    curiosity can you Pseudocode the if loop for me if you have a quick
    second? I don't quite understand how it works. Thanks again, keep up
    the great work.
    Steve


    Gord Dibben wrote:
    > By formula...........
    >
    > In B1 enter =IF(A1="","",A1)
    >
    > Drag/copy down column B as far as you wish.
    >
    > Event code..................
    >
    > Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    > 'when entering data in a cell in Col A
    > On Error GoTo enditall
    > Application.EnableEvents = False
    > If Target.Cells.Column = 1 Then
    > n = Target.Row
    > If Excel.Range("A" & n).Value <> "" Then
    > Excel.Range("B" & n).Value = Excel.Range("A" & n).Value
    > End If
    > End If
    > enditall:
    > Application.EnableEvents = True
    > End Sub
    >
    > Right-click on the sheet tab and "View Code".
    >
    > Copy/paste the code into that module.
    >
    >
    > Gord Dibben MS Excel MVP
    >
    > On 11 Jul 2006 07:16:17 -0700, "nemadrias" <[email protected]> wrote:
    >
    > >Hi -
    > >Can anyone help me figure this out? I think I need a "With" loop, but
    > >haven't really worked with them yet.
    > >
    > >I have a column of empty cells. What I want to be able to do is copy
    > >whatever is typed in any of those cells to the cell immediately to the
    > >right of them in the column immediately to the right. I need to be
    > >able to do this in the event (leaveCell) or whatever the event would be
    > >called, basically as soon as the cursor leaves the cell (enter, tab,
    > >click, whatever....) Is there a good way to do this?? Thanks a ton!
    > >Steve



  4. #4
    Gord Dibben
    Guest

    Re: Copy cells to neighbor column after leaving the cell

    Not sure what Pseudocode is but.........

    If Target.Cells.Column =1 means column A

    n =TargetRow means any row in Column A

    If Excel.Range("A" & n).Value <> "" means if An is not empty then stuff the
    value of An into Bn as you leave An

    Excel.Range("B" & n).Value = Excel.Range("A" & n).Value

    ...................................................................

    =IF(A1="","",A1)

    The formula method simply reads If A1 is empty, have B1 look empty also but if
    A1 has a value, return that to B1


    Gord

    On 11 Jul 2006 08:44:54 -0700, "nemadrias" <[email protected]> wrote:

    >FANTASTIC!!! Thank you so much - the code is what I needed. Out of
    >curiosity can you Pseudocode the if loop for me if you have a quick
    >second? I don't quite understand how it works. Thanks again, keep up
    >the great work.
    >Steve
    >
    >
    >Gord Dibben wrote:
    >> By formula...........
    >>
    >> In B1 enter =IF(A1="","",A1)
    >>
    >> Drag/copy down column B as far as you wish.
    >>
    >> Event code..................
    >>
    >> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    >> 'when entering data in a cell in Col A
    >> On Error GoTo enditall
    >> Application.EnableEvents = False
    >> If Target.Cells.Column = 1 Then
    >> n = Target.Row
    >> If Excel.Range("A" & n).Value <> "" Then
    >> Excel.Range("B" & n).Value = Excel.Range("A" & n).Value
    >> End If
    >> End If
    >> enditall:
    >> Application.EnableEvents = True
    >> End Sub
    >>
    >> Right-click on the sheet tab and "View Code".
    >>
    >> Copy/paste the code into that module.
    >>
    >>
    >> Gord Dibben MS Excel MVP
    >>
    >> On 11 Jul 2006 07:16:17 -0700, "nemadrias" <[email protected]> wrote:
    >>
    >> >Hi -
    >> >Can anyone help me figure this out? I think I need a "With" loop, but
    >> >haven't really worked with them yet.
    >> >
    >> >I have a column of empty cells. What I want to be able to do is copy
    >> >whatever is typed in any of those cells to the cell immediately to the
    >> >right of them in the column immediately to the right. I need to be
    >> >able to do this in the event (leaveCell) or whatever the event would be
    >> >called, basically as soon as the cursor leaves the cell (enter, tab,
    >> >click, whatever....) Is there a good way to do this?? Thanks a ton!
    >> >Steve


    Gord Dibben MS Excel MVP

  5. #5
    nemadrias
    Guest

    Re: Copy cells to neighbor column after leaving the cell

    Pseudocode is just any code in layman's terms....exactly as you did.
    Thanks again for all your help.
    Steve

    Gord Dibben wrote:
    > Not sure what Pseudocode is but.........
    >
    > If Target.Cells.Column =1 means column A
    >
    > n =TargetRow means any row in Column A
    >
    > If Excel.Range("A" & n).Value <> "" means if An is not empty then stuff the
    > value of An into Bn as you leave An
    >
    > Excel.Range("B" & n).Value = Excel.Range("A" & n).Value
    >
    > ..................................................................
    >
    > =IF(A1="","",A1)
    >
    > The formula method simply reads If A1 is empty, have B1 look empty also but if
    > A1 has a value, return that to B1
    >
    >
    > Gord
    >
    > On 11 Jul 2006 08:44:54 -0700, "nemadrias" <[email protected]> wrote:
    >
    > >FANTASTIC!!! Thank you so much - the code is what I needed. Out of
    > >curiosity can you Pseudocode the if loop for me if you have a quick
    > >second? I don't quite understand how it works. Thanks again, keep up
    > >the great work.
    > >Steve
    > >
    > >
    > >Gord Dibben wrote:
    > >> By formula...........
    > >>
    > >> In B1 enter =IF(A1="","",A1)
    > >>
    > >> Drag/copy down column B as far as you wish.
    > >>
    > >> Event code..................
    > >>
    > >> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    > >> 'when entering data in a cell in Col A
    > >> On Error GoTo enditall
    > >> Application.EnableEvents = False
    > >> If Target.Cells.Column = 1 Then
    > >> n = Target.Row
    > >> If Excel.Range("A" & n).Value <> "" Then
    > >> Excel.Range("B" & n).Value = Excel.Range("A" & n).Value
    > >> End If
    > >> End If
    > >> enditall:
    > >> Application.EnableEvents = True
    > >> End Sub
    > >>
    > >> Right-click on the sheet tab and "View Code".
    > >>
    > >> Copy/paste the code into that module.
    > >>
    > >>
    > >> Gord Dibben MS Excel MVP
    > >>
    > >> On 11 Jul 2006 07:16:17 -0700, "nemadrias" <[email protected]> wrote:
    > >>
    > >> >Hi -
    > >> >Can anyone help me figure this out? I think I need a "With" loop, but
    > >> >haven't really worked with them yet.
    > >> >
    > >> >I have a column of empty cells. What I want to be able to do is copy
    > >> >whatever is typed in any of those cells to the cell immediately to the
    > >> >right of them in the column immediately to the right. I need to be
    > >> >able to do this in the event (leaveCell) or whatever the event would be
    > >> >called, basically as soon as the cursor leaves the cell (enter, tab,
    > >> >click, whatever....) Is there a good way to do this?? Thanks a ton!
    > >> >Steve

    >
    > Gord Dibben MS Excel MVP



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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