Consulting

Results 1 to 2 of 2

Thread: Macro with sum formula

  1. #1

    Macro with sum formula

    Hi,

    I have this code:

     
    Sub sikumMhM()
     r1 = Range("outputMhm").End(xlDown).Row + 1
     r2 = Range("outputMhm").Row + 1
     c1 = Range("mhm").Column
     c2 = c1 + Range("mhm").Columns.Count - 2
     c3 = Range("outputMhm").Column
     c4 = col - 2
     
      Range(Cells(r1, c3), Cells(r1, c2)).Select
      Selection.Font.Size = 13
      Selection.Borders(xlEdgeTop).Weight = xlThick
     
      Cells(r1, c3) = "îçî"
      For col = c1 To c2
      If Cells(Range("MHM").Row, col) = "MHM" Then Cells(r1, col).FormulaR1C1
     = "=SUM(R" & r2 & "C:R[-1]C)/sum(R" & r2 & "C" & col - 2 & ":R[-1]C[-2])"
                         Next col
     
    End Sub
    It works fine except for the fact the I get the dollar sign for the first row, for example : sum(R$8:R48)/sum($D$848)

    How do I get rid of the $ sign?

    Thanks,
    Udi

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is this what you want

    [vba]

    For col = c1 To c2
    If Cells(Range("MHM").Row, col) = "MHM" Then Cells(r1, col).FormulaR1C1 = _
    "=SUM(R[" & r2 & "]C:R[-1]C)/sum(R" & r2 & "C" & col - 2 & ":R[-1]C[-2])"
    Next col
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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