Consulting

Results 1 to 3 of 3

Thread: Excel vba copy paste with formulas

  1. #1

    Excel vba copy paste with formulas

    Hi, I have this codes below that perform copying of records that includes the formula. May i ask your assistnace on how to do this in vba macro. thanks.

            If Not rng1 Is Nothing Then
                'Following line assigns to rngToCopy the Range from cell below the found rng1 _
                'to the last used cell in the column
                Set rngToCopy = Range(rng1.Offset(1, 0), .Cells(.Rows.Count, rng1.Column).End(xlUp))
            Else
                MsgBox "Value " & TargetDate & " not found." & vbCrLf & "Processing terminated."
                Exit Sub
            End If
            Stop
            
            Set rngNextDestin = Range(rng1.Offset(1, 0), .Cells(.Rows.Count, rng1.Column).End(xlUp)).Offset(0, 1)
            Debug.Print rngNextDestin.Address
            rngNextDestin.Resize(rngToCopy.Rows.Count, rngToCopy.Columns.Count) = rngToCopy.Value  --this portion will copy that includes formulas.

  2. #2
    rngToCopy.FormulaR1C1= "=rc[-1]"

    copies value from one cell to left for each row, change formula to suit

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    rngToCopy.copy rngNextDestin
    will copy formulas, formats, the lot
    ____________________________________________
    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
  •