# Thread: Macro – divide by last column.

1. Registered User
Join Date
Nov 2004
Posts
78

## Unanswered: Macro – divide by last column.

I have this Macro in excel and can not figure out how to set the formula to devide a cell by the last column.

Currently, this line divides the cell by a number, (in my case it is 12 since I have 12 columns)

Cells(LastRow - 1, i + 1).FormulaR1C1 = "=RC[-1]/" & (LastColumn)

Thank you

Code:
```Sub (Test)
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%"
''
LastColumn = Range("IV1").End(xlToLeft).Column
'''
Cells(LastRow - 1, i + 1).FormulaR1C1 = "=RC[-1]/" & (LastColumn)
Cells(LastRow - 1, i + 1).Select
Selection.AutoFill Destination:=Range(Cells(2, i + 1), Cells(LastRow - 1, i + 1)), Type:=xlFillDefault
Next i

Columns(LastColumn + LastColumn - 1).Delete
End sub```

2. Registered User
Join Date
Apr 2004
Location
Derbyshire, UK
Posts
805
Hi

I think your query is a little ambiguous but does this do it ??

Cells(LastColumn - 1, i + 1).FormulaR1C1 = "=RC[-1]/RC" & LastColumn & ""

If not, it might give you a clue !!??

MTB

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•