Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default copying a formula to another cell

This is a trivial question but I have run into a wall trying to find the
answer.
I have a formula in a cell which I want to copy to the cells below with a
simple routine. A sample routine looks like this:

Public Sub test_case()
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1).Formula = .Cells(1, 1)
Next
End With
End Sub

In cell(1,1) is the sample formula =RC2/RC3. The routine, as it is, copies
the formula down to the 4 cells below. =RC2/RC3 shows in the cells but it is
not a formula that equates to the value. How do I change the code to get it
to be a real formula? Any help will be greatly appreciated
--
russ
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default copying a formula to another cell

Perhaps this would be the way to go

Dim r As Long
Dim s As String
s = "=RC2/RC3 "
Cells(1, 1) = s
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1).Formula = s
Next
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default copying a formula to another cell

You were not too far off.

Public Sub test_case()
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1).Formula = .Cells(1, 1).Formula
Next
End With
End Sub

However, It copies the formula as absolute reference. i.e. If your formula
is =b1+c1, then each cell in the range will be =b1+c1 and not =b2+c2, =b3+c3,
etc.




"Russ" wrote:

This is a trivial question but I have run into a wall trying to find the
answer.
I have a formula in a cell which I want to copy to the cells below with a
simple routine. A sample routine looks like this:

Public Sub test_case()
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1).Formula = .Cells(1, 1)
Next
End With
End Sub

In cell(1,1) is the sample formula =RC2/RC3. The routine, as it is, copies
the formula down to the 4 cells below. =RC2/RC3 shows in the cells but it is
not a formula that equates to the value. How do I change the code to get it
to be a real formula? Any help will be greatly appreciated
--
russ

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default copying a formula to another cell

I think this might be more what you are looking for.

Sub autFil()
Set SourceRange = Sheets(1).Range("A1")
Set FillRange = Sheets(1).Range("A1:A5")
Range("A1").Formula = "=b1/c1"
SourceRange.Autofill FillRange
End Sub


"Russ" wrote in message
...
This is a trivial question but I have run into a wall trying to find the
answer.
I have a formula in a cell which I want to copy to the cells below with a
simple routine. A sample routine looks like this:

Public Sub test_case()
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1).Formula = .Cells(1, 1)
Next
End With
End Sub

In cell(1,1) is the sample formula =RC2/RC3. The routine, as it is,
copies
the formula down to the 4 cells below. =RC2/RC3 shows in the cells but it
is
not a formula that equates to the value. How do I change the code to get
it
to be a real formula? Any help will be greatly appreciated
--
russ



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default copying a formula to another cell

Hi Russ,

If you want the formula that is copied to be relative in the other cells
then you need to copy the cell not make the others equal to the original cell.

Public Sub test_case()
'Creates formulas and makes them relative
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(1, 1).Copy .Cells(r, 1)
Next
End With
End Sub


If you want the exact same formula in the other rows then this way.
Public Sub test_case2()
'Copies the exact same formula to other cells
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1) = .Cells(1, 1).Formula
Next
End With
End Sub




--
Regards,

OssieMac


"Russ" wrote:

This is a trivial question but I have run into a wall trying to find the
answer.
I have a formula in a cell which I want to copy to the cells below with a
simple routine. A sample routine looks like this:

Public Sub test_case()
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1).Formula = .Cells(1, 1)
Next
End With
End Sub

In cell(1,1) is the sample formula =RC2/RC3. The routine, as it is, copies
the formula down to the 4 cells below. =RC2/RC3 shows in the cells but it is
not a formula that equates to the value. How do I change the code to get it
to be a real formula? Any help will be greatly appreciated
--
russ



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default copying a formula to another cell

Thanks to all of you. I now have the solution.
--
russ


"Russ" wrote:

This is a trivial question but I have run into a wall trying to find the
answer.
I have a formula in a cell which I want to copy to the cells below with a
simple routine. A sample routine looks like this:

Public Sub test_case()
Dim r As Long
With ActiveWorkbook.Sheets(1)
For r = 2 To 5
.Cells(r, 1).Formula = .Cells(1, 1)
Next
End With
End Sub

In cell(1,1) is the sample formula =RC2/RC3. The routine, as it is, copies
the formula down to the 4 cells below. =RC2/RC3 shows in the cells but it is
not a formula that equates to the value. How do I change the code to get it
to be a real formula? Any help will be greatly appreciated
--
russ

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula for copying a value in a cell until that value changes Eric D Excel Discussion (Misc queries) 4 October 2nd 08 05:07 PM
copying formula to another cell dmack Excel Discussion (Misc queries) 4 January 11th 07 05:33 PM
Formula for copying tap info into a cell James Excel Worksheet Functions 2 November 9th 06 06:15 PM
copying cell formula from one workbook to another Cel Excel Programming 0 July 30th 05 10:20 AM
Copying cell data without the formula Oreg[_21_] Excel Programming 2 June 16th 05 06:51 PM


All times are GMT +1. The time now is 10:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"