+ Reply to Thread
Results 1 to 9 of 9

copy down formular from the row above

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2003
    Posts
    20

    copy down formular from the row above

    Hi Everybody,

    I need to copy down the formular from column C&D from the row above, every row is one week, so the last row is week 52.
    The code I have it copy the exact formular from the cell, it is not copy DOWN the formular.

    Any help will be appreciate it.

    Thanks.

    Sub copyFormulaString()
     Dim LastRow As Long
     Dim m_copy As String
     
        m_copy = Range("M1").Value
        
        LastRow = Sheets("Sheet1").Cells(53, "c").End(xlUp).Row
        
        stRow = Sheets("Sheet1").Range("D" & Rows.Count).End(xlUp).Row
            Sheets("Sheet1").Select
            Range(m_copy).Formula = Range("C3").Formula

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: copy down formular from the row above

    Hi coolwater,

    It looks like your are copying the .Value into m_copy instead of everything about the cell.

    Try changing two lines
    Change Dim m_copy As String to Dim m_copy As Range
    Then change m_copy = Range("M1").Value to m_copy = Range("M1")

    I'd need more code or a sample of the workbook to suggest more.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    02-03-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: copy down formular from the row above

    Hi MarvinP, Thanks for your reply. I can't upload a file.

    So here is an example, hope it can explain better.
    the week number is in column A,2011 in column B,2012 column C ( B&C) are the ones I need to copy down the formular.
    The C6 is in cell "M1"



    2011 2012 week on week Cell update to C6
    week1 200 100
    week2 200 200 100%
    week3 200 300 50%
    week4 200 400 33%
    week5 200 520 30%
    week6 200
    week7 200
    week8 200
    week9 200
    week10 200
    week11 200
    week12 200
    week13 200
    week14 200

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: copy down formular from the row above

    Hi coolwater,

    To attach a file, click on the Go Advanced below the normal message area and then on the Paper Clip Icon above the advanced message area. This will open a dialog that allows you to select a file and upload it to this site.

  5. #5
    Registered User
    Join Date
    02-03-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: copy down formular from the row above

    I saw that function, it's work computer security reason,I can't upload files to the web site.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: copy down formular from the row above

    Is there a reason you need to do this using VBA instead of simply dragging it down a cell?

  7. #7
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: copy down formular from the row above

    If you just want to copy the formula, I would suggest
    Range(m_copy).FormulaR1C1 = Range("C3").FormulaR1C1
    Good luck.

  8. #8
    Registered User
    Join Date
    02-03-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: copy down formular from the row above

    Hi OEGO, I used your code and it works, however it is only copy the formular in column C, What should I change to get formular copy down for Column D as well.

    what's the "R1C1" mean?
    Thanks for your help.

    Regards

  9. #9
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: copy down formular from the row above

    It is unclear from your code, but possibly
    With Range(m_copy)
       .FormulaR1C1 = Range("C3").FormulaR1C1
       .Offset(, 1).FormulaR1C1 = Range("D3").FormulaR1C1
    End With
    R1C1 is the reference style (as opposed to A1).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1