PC Review


Reply
Thread Tools Rate Thread

Copy and Paste using VBA.

 
 
spreadsheetlady
Guest
Posts: n/a
 
      15th Apr 2010
Hi,

If A1 is not blank then Copy A1 and Paste in A2:A7.

I originally had simple links in cells A2:A7 that connected to A1. But
sometimes one of the cells in range A2:A7 may manually have a value typed in
them, which erases the link to A1.

I thought trying this using VBA would eliminate the cell linkage loss.

I'm new to VBA.

Any suggestions would be appreciated.
Amy
 
Reply With Quote
 
 
 
 
B Lynn B
Guest
Posts: n/a
 
      15th Apr 2010
Right-click the tab for the sheet where you want this to apply, select "View
Code", then paste in the code below. If you really want it to behave the
same as a link, then I'd take out the part about range("a1") <> "" (including
the underscore character and the line break before "Then"). That way,
whatever is in A1 will always be in A2:A7.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1")) Is Nothing _
And Range("A1") <> "" Then
Range("A2:A7").Value = Range("A1").Value
End If

End Sub


"spreadsheetlady" wrote:

> Hi,
>
> If A1 is not blank then Copy A1 and Paste in A2:A7.
>
> I originally had simple links in cells A2:A7 that connected to A1. But
> sometimes one of the cells in range A2:A7 may manually have a value typed in
> them, which erases the link to A1.
>
> I thought trying this using VBA would eliminate the cell linkage loss.
>
> I'm new to VBA.
>
> Any suggestions would be appreciated.
> Amy

 
Reply With Quote
 
spreadsheetlady
Guest
Posts: n/a
 
      16th Apr 2010
Thank-you B Lynn B. It works perfectly and is exactly what I wanted.
Amy



"B Lynn B" wrote:

> Right-click the tab for the sheet where you want this to apply, select "View
> Code", then paste in the code below. If you really want it to behave the
> same as a link, then I'd take out the part about range("a1") <> "" (including
> the underscore character and the line break before "Then"). That way,
> whatever is in A1 will always be in A2:A7.
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> If Not Intersect(Target, Range("A1")) Is Nothing _
> And Range("A1") <> "" Then
> Range("A2:A7").Value = Range("A1").Value
> End If
>
> End Sub
>
>
> "spreadsheetlady" wrote:
>
> > Hi,
> >
> > If A1 is not blank then Copy A1 and Paste in A2:A7.
> >
> > I originally had simple links in cells A2:A7 that connected to A1. But
> > sometimes one of the cells in range A2:A7 may manually have a value typed in
> > them, which erases the link to A1.
> >
> > I thought trying this using VBA would eliminate the cell linkage loss.
> >
> > I'm new to VBA.
> >
> > Any suggestions would be appreciated.
> > Amy

 
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
How do I get copy/paste to copy/paste text and not the whole page =?Utf-8?B?Q2Fyb2wgSi4=?= Microsoft Word Document Management 1 6th May 2005 09:03 PM
Copy and Paste macro needs to paste to a changing cell reference =?Utf-8?B?bG91bG91?= Microsoft Excel Programming 0 24th Feb 2005 10:29 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel New Users 0 10th Mar 2004 07:06 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel Misc 0 10th Mar 2004 07:06 AM
Re: Copy/Paste in Excel prints highlighted cells and does not paste Dave Peterson Microsoft Excel Misc 0 30th Jul 2003 11:08 PM


Features
 

Advertising
 

Newsgroups
 


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