PC Review


Reply
Thread Tools Rate Thread

Copy Formula Issue

 
 
Liz
Guest
Posts: n/a
 
      2nd May 2008
I have a macro that copies a row and pastes it immediately below. The cells
in the row being copied each a a different formula in them and I want these
individual formulas to be copied to the matching cells in the new row. My
code does this however the cell references in the new row is not the same as
the cell references in the row above it and should be. Is this an automatic
thing that Excel does and how can I turn it off or code it so that the
formula is copied exactly as is!

Any assistance would be greatly appreciated.

L
--
It it''''s meant to be, it won''''t pass you by!
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      2nd May 2008
L,

Try the code below - written to copy the row of the activecell.

HTH,
Bernie
MS Excel MVP


Sub CopyRowWithExactFormulas()
Dim myCalc As Variant

With Application
.ScreenUpdating = False
myCalc = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
End With

With ActiveCell.EntireRow
SAFormulaToText .Cells
.Copy
.Insert xlDown
SATextToFormula .Cells
SATextToFormula .Offset(-1, 0).Cells
End With

With Application
.ScreenUpdating = True
.Calculation = myCalc
.EnableEvents = True
End With
End Sub

Sub SAFormulaToText(myR As Range)
Dim myCell As Range
On Error Resume Next
For Each myCell In myR.SpecialCells(xlCellTypeFormulas)
myCell.Formula = "'" & myCell.Formula
Next myCell
End Sub

Sub SATextToFormula(myR As Range)
Dim myCell As Range
On Error Resume Next
For Each myCell In myR
myCell.Formula = myCell.Text
Next myCell
End Sub


"Liz" <(E-Mail Removed)> wrote in message
news:81D9652B-10C6-4444-A775-(E-Mail Removed)...
>I have a macro that copies a row and pastes it immediately below. The cells
> in the row being copied each a a different formula in them and I want these
> individual formulas to be copied to the matching cells in the new row. My
> code does this however the cell references in the new row is not the same as
> the cell references in the row above it and should be. Is this an automatic
> thing that Excel does and how can I turn it off or code it so that the
> formula is copied exactly as is!
>
> Any assistance would be greatly appreciated.
>
> L
> --
> It it''''s meant to be, it won''''t pass you by!



 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      2nd May 2008
I don't believe you can change the default way Excel copies formulas to
another cell. You can however, if your formula allows, make the formulas
absolute references, example: $A$1 vs. A1. Then the formulas will be copied
"as is". Example

Alan

"Liz" wrote:

> I have a macro that copies a row and pastes it immediately below. The cells
> in the row being copied each a a different formula in them and I want these
> individual formulas to be copied to the matching cells in the new row. My
> code does this however the cell references in the new row is not the same as
> the cell references in the row above it and should be. Is this an automatic
> thing that Excel does and how can I turn it off or code it so that the
> formula is copied exactly as is!
>
> Any assistance would be greatly appreciated.
>
> L
> --
> It it''''s meant to be, it won''''t pass you by!

 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      2nd May 2008
Alan,

Thanks for your quick response. Unfortunately it only worked partly. Here is
my formula in the cell above;

=SUM('Inc.-Inj. Numbers'!V165)

after running the copy function (using the absolute reference logic) here is
the formula in the new row;

=SUM('Inc.-Inj. Numbers'!V166)

This worksheet obviously totals numbers but it's numbers from another
worksheet in the same workbook. A fact I failed to mention in my first post.
My Bad!

Only after reading your response (a big DUH moment for me of course! -
should have clued in on that myself but could not see the forest for the
trees), did I realize that perhaps I need to rethink how I do this as I must
make sure that the reference for the worksheet "Inc.-In.Number" is there
first anyway and the column will change as this will be a new column on the
"Inc.-In.Number" sheet but the row will be the same (each column on the
"Inc.-In.Number" sheet is a new month).

Any hints you can give me in this direction would be greatly appreciated!

Regards,

Liz
--
It it's meant to be, it won't pass you by!


"Alan" wrote:

> I don't believe you can change the default way Excel copies formulas to
> another cell. You can however, if your formula allows, make the formulas
> absolute references, example: $A$1 vs. A1. Then the formulas will be copied
> "as is". Example
>
> Alan
>
> "Liz" wrote:
>
> > I have a macro that copies a row and pastes it immediately below. The cells
> > in the row being copied each a a different formula in them and I want these
> > individual formulas to be copied to the matching cells in the new row. My
> > code does this however the cell references in the new row is not the same as
> > the cell references in the row above it and should be. Is this an automatic
> > thing that Excel does and how can I turn it off or code it so that the
> > formula is copied exactly as is!
> >
> > Any assistance would be greatly appreciated.
> >
> > L
> > --
> > It it''''s meant to be, it won''''t pass you by!

 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      2nd May 2008
Thanks to Bernie for submitting that code. It will work great for you if you
want to slip that code into your module.

As far as your formula goes:

=SUM('Inc.-Inj. Numbers'!V165)

To make that an absolute reference formula, you need to add the $ like this:

=SUM('Inc.-Inj. Numbers'!$V$165)


Alan


> Alan,
>
> Thanks for your quick response. Unfortunately it only worked partly. Here is
> my formula in the cell above;
>
> =SUM('Inc.-Inj. Numbers'!V165)
>
> after running the copy function (using the absolute reference logic) here is
> the formula in the new row;
>
> =SUM('Inc.-Inj. Numbers'!V166)
>
> This worksheet obviously totals numbers but it's numbers from another
> worksheet in the same workbook. A fact I failed to mention in my first post.
> My Bad!
>
> Only after reading your response (a big DUH moment for me of course! -
> should have clued in on that myself but could not see the forest for the
> trees), did I realize that perhaps I need to rethink how I do this as I must
> make sure that the reference for the worksheet "Inc.-In.Number" is there
> first anyway and the column will change as this will be a new column on the
> "Inc.-In.Number" sheet but the row will be the same (each column on the
> "Inc.-In.Number" sheet is a new month).
>
> Any hints you can give me in this direction would be greatly appreciated!
>
> Regards,
>
> Liz
> --
> It it's meant to be, it won't pass you by!
>
>
> "Alan" wrote:
>
> > I don't believe you can change the default way Excel copies formulas to
> > another cell. You can however, if your formula allows, make the formulas
> > absolute references, example: $A$1 vs. A1. Then the formulas will be copied
> > "as is". Example
> >
> > Alan
> >
> > "Liz" wrote:
> >
> > > I have a macro that copies a row and pastes it immediately below. The cells
> > > in the row being copied each a a different formula in them and I want these
> > > individual formulas to be copied to the matching cells in the new row. My
> > > code does this however the cell references in the new row is not the same as
> > > the cell references in the row above it and should be. Is this an automatic
> > > thing that Excel does and how can I turn it off or code it so that the
> > > formula is copied exactly as is!
> > >
> > > Any assistance would be greatly appreciated.
> > >
> > > L
> > > --
> > > It it''''s meant to be, it won''''t pass you by!

 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      2nd May 2008
Bernie,

Thanks for the replay and the code! Will let you know how it goes.

Regards,

L
--
It it's meant to be, it won't pass you by!


"Bernie Deitrick" wrote:

> L,
>
> Try the code below - written to copy the row of the activecell.
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> Sub CopyRowWithExactFormulas()
> Dim myCalc As Variant
>
> With Application
> .ScreenUpdating = False
> myCalc = .Calculation
> .Calculation = xlCalculationManual
> .EnableEvents = False
> End With
>
> With ActiveCell.EntireRow
> SAFormulaToText .Cells
> .Copy
> .Insert xlDown
> SATextToFormula .Cells
> SATextToFormula .Offset(-1, 0).Cells
> End With
>
> With Application
> .ScreenUpdating = True
> .Calculation = myCalc
> .EnableEvents = True
> End With
> End Sub
>
> Sub SAFormulaToText(myR As Range)
> Dim myCell As Range
> On Error Resume Next
> For Each myCell In myR.SpecialCells(xlCellTypeFormulas)
> myCell.Formula = "'" & myCell.Formula
> Next myCell
> End Sub
>
> Sub SATextToFormula(myR As Range)
> Dim myCell As Range
> On Error Resume Next
> For Each myCell In myR
> myCell.Formula = myCell.Text
> Next myCell
> End Sub
>
>
> "Liz" <(E-Mail Removed)> wrote in message
> news:81D9652B-10C6-4444-A775-(E-Mail Removed)...
> >I have a macro that copies a row and pastes it immediately below. The cells
> > in the row being copied each a a different formula in them and I want these
> > individual formulas to be copied to the matching cells in the new row. My
> > code does this however the cell references in the new row is not the same as
> > the cell references in the row above it and should be. Is this an automatic
> > thing that Excel does and how can I turn it off or code it so that the
> > formula is copied exactly as is!
> >
> > Any assistance would be greatly appreciated.
> >
> > L
> > --
> > It it''''s meant to be, it won''''t pass you by!

>
>
>

 
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
I copy a formula and the results copy from the original cell =?Utf-8?B?YnJvb2tseW5zZA==?= Microsoft Excel Misc 1 23rd Jun 2007 01:35 AM
copy formula down a column and have cell references change within formula brad Microsoft Excel New Users 5 13th May 2007 04:38 PM
Copy/Paste how to avoid the copy of formula cells w/o calc values =?Utf-8?B?RGVubmlz?= Microsoft Excel Misc 10 2nd Mar 2006 10:47 PM
Re: Formula Copy Issue Frank Kabel Microsoft Excel Worksheet Functions 0 16th Apr 2004 02:06 PM
Re: Formula Copy Issue Jason Morin Microsoft Excel Worksheet Functions 0 16th Apr 2004 02:01 PM


Features
 

Advertising
 

Newsgroups
 


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