If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > copy a formula only to the last 26 rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-07, 12:22
Joe1 Joe1 is offline
Registered User
 
Join Date: Nov 2004
Posts: 77
copy a formula only to the last 26 rows

I did not design this macro and the designer is not available yet. Maybe you can help me.
Currently the
Cells(LastRow - 1, i + 1).FormulaR1C1 = "=RC[-1]/R[-13]C[-1]-1"
is being copied to all rows.
What line needs to be changed in order to copy this formula only to the last 26 rows?

Thank you.

Application.ScreenUpdating = False
Dim LastColumn, LastRow As Integer
Cells.MergeCells = False
Rows("1:3").Delete Shift:=xlUp
Columns("A:A").Delete Shift:=xlToLeft
LastColumn = Range("IV1").End(xlToLeft).Column
LastRow = Range("A65536").End(xlUp).Row + 1

For i = 2 To (LastColumn + LastColumn - 1) Step 2
Columns(i + 1).Insert
Cells(1, i + 1).Value = "% of Grth"
Columns(i + 1).NumberFormat = "0%"
Columns(i + 1).ColumnWidth = 4.14
Cells(LastRow - 1, i + 1).FormulaR1C1 = "=RC[-1]/R[-13]C[-1]-1"
Cells(LastRow - 1, i + 1).Select
Selection.AutoFill Destination:=Range(Cells(2, i + 1), Cells(LastRow - 1, i + 1)), Type:=xlFillDefault
Next i
Reply With Quote
  #2 (permalink)  
Old 01-10-07, 08:15
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi Joe

This maybe what you want
Code:
If LastRow > 25 Then
        For i = 2 To (LastColumn * 2 - 1) Step 2
            If LastColumn > 0 Then
                Columns(i + 1).Insert
                Cells(1, i + 1).Value = "% of Grth"
                Columns(i + 1).NumberFormat = "0%"
                Columns(i + 1).ColumnWidth = 4.14
                Cells(LastRow - 1, i + 1).FormulaR1C1 = "=RC[-1]/R[-13]C[-1]-1"
                Cells(LastRow - 1, i + 1).Select
                Selection.AutoFill Destination:=Range(Cells(LastRow - 25, i + 1), Cells(LastRow - 1, i + 1)), Type:=xlFillDefault
            End If
        Next i
    End If
ie change

Selection.AutoFill Destination:=Range(Cells(2, i + 1), Cells(LastRow - 1, i + 1)), Type:=xlFillDefault

to
Selection.AutoFill Destination:=Range(Cells(LastRow - 25, i + 1), Cells(LastRow - 1, i + 1)), Type:=xlFillDefault


Is that it ??


MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On