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 > Macro – divide by last column.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-07, 12:23
Joe1 Joe1 is offline
Registered User
 
Join Date: Nov 2004
Posts: 77
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
Reply With Quote
  #2 (permalink)  
Old 01-10-07, 08:55
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
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
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