PC Review


Reply
Thread Tools Rate Thread

Copy and Paste exact formula

 
 
Joshua
Guest
Posts: n/a
 
      14th Jan 2009
I'm trying to write a 2 macros. The 1st to copy the exact formulas of
a range and the 2nd to paste the exact formulas from the copied range
into a selected range. For example, lets say cells A1, B1, and C1 all
contain formulas and I would like to copy those exact formulas into
A2, B2, and C2. I would like this macro to also work when the formula
(s) contain references to external workbooks. C

can anyone help me solve this?

thanks!

J
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      14th Jan 2009
This is kind of a dumb example. It assumes that you select cells and run
copyit and select the destination and run pasteit

The two selections must have the same number of cells.

Dim stuff(1000) As Variant

Sub copyit()
i = 0
For Each r In Selection
stuff(i) = r.Formula
i = i + 1
Next
End Sub

Sub pasteit()
i = 0
For Each r In Selection
r.Formula = stuff(i)
i = i + 1
Next
End Sub

--
Gary''s Student - gsnu2007K


"Joshua" wrote:

> I'm trying to write a 2 macros. The 1st to copy the exact formulas of
> a range and the 2nd to paste the exact formulas from the copied range
> into a selected range. For example, lets say cells A1, B1, and C1 all
> contain formulas and I would like to copy those exact formulas into
> A2, B2, and C2. I would like this macro to also work when the formula
> (s) contain references to external workbooks. C
>
> can anyone help me solve this?
>
> thanks!
>
> J
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      14th Jan 2009
Do you absolutely have to have 2 macros to do this or would a single macro
be okay?

Sub DuplicateFormulasExactly()
Range("A2:C2").Formula = Range("A1:C1).Formula
End Sub

--
Rick (MVP - Excel)


"Joshua" <(E-Mail Removed)> wrote in message
news:d1744c38-52f6-4f65-b09a-(E-Mail Removed)...
> I'm trying to write a 2 macros. The 1st to copy the exact formulas of
> a range and the 2nd to paste the exact formulas from the copied range
> into a selected range. For example, lets say cells A1, B1, and C1 all
> contain formulas and I would like to copy those exact formulas into
> A2, B2, and C2. I would like this macro to also work when the formula
> (s) contain references to external workbooks. C
>
> can anyone help me solve this?
>
> thanks!
>
> J


 
Reply With Quote
 
Joshua
Guest
Posts: n/a
 
      20th Jan 2009
On Jan 14, 2:15*pm, "Rick Rothstein"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> Do you absolutely have to have 2 macros to do this or would a single macro
> be okay?
>
> Sub DuplicateFormulasExactly()
> * Range("A2:C2").Formula = Range("A1:C1).Formula
> End Sub
>
> --
> Rick (MVP - Excel)
>
> "Joshua" <joshua.moa...@gmail.com> wrote in message
>
> news:d1744c38-52f6-4f65-b09a-(E-Mail Removed)...
>
> > I'm trying to write a 2 macros. *The 1st to copy the exact formulas of
> > a range and the 2nd to paste the exact formulas from the copied range
> > into a selected range. *For example, lets say cells A1, B1, and C1 all
> > contain formulas and I would like to copy those exact formulas into
> > A2, B2, and C2. *I would like this macro to also work when the formula
> > (s) contain references to external workbooks. *C

>
> > can anyone help me solve this?

>
> > thanks!

>
> > J


Gary's Student - when i run your copyit macro I get a compile error on
the line stuff(i) = r.Formula which says "compile error sub or
function not defined". Could you please help me fix this? Thanks!

Yes, this needs to be 2 seperate macros b/c the purpose of it is to
select and copy the formulas of cells in the first selected range and
paste those exact formulas in a different selected range of the same
number of cells. I would like this to work for any range selected for
copy and any range selected for paste so the second solution doesnt
work for me.


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      21st Jan 2009
Give this single macro solution a try. Select the range of formulas you want
to copy, run the macro and, in response to the InputBox question, either
type in or select with your mouse a single cell which represents the
top/left corner of the range you wish to copy to.

Sub DuplicateFormulasExactly()
Dim S As Range
Dim CopyAddr As Range
Set S = Selection
Set CopyAddr = Application.InputBox( _
"Click on the cell to begin copying at", _
"Input 'Copy To' Cell", Type:=8)
CopyAddr.Resize(S.Rows.Count, S.Columns.Count).Formula = S.Formula
End Sub

--
Rick (MVP - Excel)


"Joshua" <(E-Mail Removed)> wrote in message
news:180dfb86-e894-45be-b045-(E-Mail Removed)...
On Jan 14, 2:15 pm, "Rick Rothstein"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> Do you absolutely have to have 2 macros to do this or would a single macro
> be okay?
>
> Sub DuplicateFormulasExactly()
> Range("A2:C2").Formula = Range("A1:C1).Formula
> End Sub
>
> --
> Rick (MVP - Excel)
>
> "Joshua" <joshua.moa...@gmail.com> wrote in message
>
> news:d1744c38-52f6-4f65-b09a-(E-Mail Removed)...
>
> > I'm trying to write a 2 macros. The 1st to copy the exact formulas of
> > a range and the 2nd to paste the exact formulas from the copied range
> > into a selected range. For example, lets say cells A1, B1, and C1 all
> > contain formulas and I would like to copy those exact formulas into
> > A2, B2, and C2. I would like this macro to also work when the formula
> > (s) contain references to external workbooks. C

>
> > can anyone help me solve this?

>
> > thanks!

>
> > J


Gary's Student - when i run your copyit macro I get a compile error on
the line stuff(i) = r.Formula which says "compile error sub or
function not defined". Could you please help me fix this? Thanks!

Yes, this needs to be 2 seperate macros b/c the purpose of it is to
select and copy the formulas of cells in the first selected range and
paste those exact formulas in a different selected range of the same
number of cells. I would like this to work for any range selected for
copy and any range selected for paste so the second solution doesnt
work for me.


 
Reply With Quote
 
Joshua
Guest
Posts: n/a
 
      23rd Jan 2009
On Jan 21, 3:12*pm, "Rick Rothstein"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> Give this single macro solution a try. Select the range of formulas you want
> to copy, run the macro and, in response to the InputBox question, either
> type in or select with your mouse a single cell which represents the
> top/left corner of the range you wish to copy to.
>
> Sub DuplicateFormulasExactly()
> * Dim S As Range
> * Dim CopyAddr As Range
> * Set S = Selection
> * Set CopyAddr = Application.InputBox( _
> * * * * * * * * * * * * * * *"Click on the cell to begin copying at", _
> * * * * * * * * * * * * * * *"Input 'Copy To' Cell", Type:=8)
> * CopyAddr.Resize(S.Rows.Count, S.Columns.Count).Formula = S.Formula
> End Sub
>
> --
> Rick (MVP - Excel)
>
> "Joshua" <joshua.moa...@gmail.com> wrote in message
>
> news:180dfb86-e894-45be-b045-(E-Mail Removed)...
> On Jan 14, 2:15 pm, "Rick Rothstein"
>
>
>
> <rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> > Do you absolutely have to have 2 macros to do this or would a single macro
> > be okay?

>
> > Sub DuplicateFormulasExactly()
> > Range("A2:C2").Formula = Range("A1:C1).Formula
> > End Sub

>
> > --
> > Rick (MVP - Excel)

>
> > "Joshua" <joshua.moa...@gmail.com> wrote in message

>
> >news:d1744c38-52f6-4f65-b09a-(E-Mail Removed)....

>
> > > I'm trying to write a 2 macros. The 1st to copy the exact formulas of
> > > a range and the 2nd to paste the exact formulas from the copied range
> > > into a selected range. For example, lets say cells A1, B1, and C1 all
> > > contain formulas and I would like to copy those exact formulas into
> > > A2, B2, and C2. I would like this macro to also work when the formula
> > > (s) contain references to external workbooks. C

>
> > > can anyone help me solve this?

>
> > > thanks!

>
> > > J

>
> Gary's Student - when i run your copyit macro I get a compile error on
> the line stuff(i) = r.Formula which says "compile error sub or
> function not defined". *Could you please help me fix this? *Thanks!
>
> Yes, this needs to be 2 seperate macros b/c the purpose of it is to
> select and copy the formulas of cells in the first selected range and
> paste those exact formulas in a different selected range of the same
> number of cells. *I would like this to work for any range selected for
> copy and any range selected for paste so the second solution doesnt
> work for me.


Yes! Thank you so much! You are the man.

J
 
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
Copy Exact Formula bongiman Microsoft Excel Misc 1 19th Jun 2009 05:58 PM
RE: Copy Exact Formula Ken Microsoft Excel Misc 0 19th Jun 2009 05:48 PM
How to do the exact copy of a formula =?Utf-8?B?TWljaGFs?= Microsoft Excel Worksheet Functions 8 20th Oct 2005 04:27 PM
exact copy/paste jmwismer Microsoft Excel Programming 6 20th Oct 2005 03:24 PM
How can I copy a picture from one excel file and paste into the exact location Stan alachniewicz Microsoft Excel Misc 1 5th Oct 2004 07:55 PM


Features
 

Advertising
 

Newsgroups
 


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