PC Review


Reply
Thread Tools Rate Thread

Copy cells to neighbor column after leaving the cell

 
 
nemadrias
Guest
Posts: n/a
 
      11th Jul 2006
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

 
Reply With Quote
 
 
 
 
Gord Dibben
Guest
Posts: n/a
 
      11th Jul 2006
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" <(E-Mail Removed)> 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


 
Reply With Quote
 
nemadrias
Guest
Posts: n/a
 
      11th Jul 2006
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" <(E-Mail Removed)> 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


 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      11th Jul 2006
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" <(E-Mail Removed)> 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" <(E-Mail Removed)> 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 With Quote
 
nemadrias
Guest
Posts: n/a
 
      12th Jul 2006
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" <(E-Mail Removed)> 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" <(E-Mail Removed)> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can I copy a number of cells in a column to a single cell ina row Bev Microsoft Excel Misc 2 3rd Jul 2008 12:11 PM
comparing a column of cell and then copy info to other cells =?Utf-8?B?S2VsbHkqKioqKioqKg==?= Microsoft Excel Misc 0 21st Mar 2006 09:51 AM
Copy column of cells to a single cell? =?Utf-8?B?bmFzdGVjaA==?= Microsoft Excel Misc 7 15th Feb 2006 12:39 PM
Re: VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? Steven Rosenberg Microsoft Excel Programming 0 5th Aug 2003 06:10 AM
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? SROSENYC Microsoft Excel Programming 1 5th Aug 2003 04:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:18 AM.