+ Reply to Thread
Results 1 to 6 of 6

Macro - Copy and Paste to a Specific Row based on the input in a cell

Hybrid View

usc1382 Macro - Copy and Paste to a... 05-22-2012, 04:23 PM
Pichingualas Re: Macro - Copy and Paste to... 05-22-2012, 04:50 PM
Pichingualas Re: Macro - Copy and Paste to... 05-22-2012, 04:53 PM
RaulRodriguez Re: Macro - Copy and Paste to... 05-22-2012, 04:55 PM
HSV Re: Macro - Copy and Paste to... 05-22-2012, 04:56 PM
usc1382 Re: Macro - Copy and Paste to... 05-22-2012, 05:05 PM
  1. #1
    Registered User
    Join Date
    10-26-2010
    Location
    USA
    MS-Off Ver
    Microsoft Office 2010
    Posts
    32

    Macro - Copy and Paste to a Specific Row based on the input in a cell

    I am trying to write a macro that will copy and paste a formula to a specific row based upon my input in a certain cell. Therefore, one time I might need to have the macro copy and paste to row 25 and the next time the macro might be required to paste the formula to row 50. I have attached the file including the basic macro. Any help would be greatly appreciated. Thank you.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Macro - Copy and Paste to a Specific Row based on the input in a cell

    Change your macro to this:

    Sub Copy_Paste()
    ' Copy_Paste Macro
    
        Application.ScreenUpdating = False
        
        Range("B3:B" & Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row).ClearContents
        Range("B2").Copy
        Range("B2:B" & Range("D1").Value).PasteSpecial
        Range("A1").Select
        
        Application.CutCopyMode = False
        
        Application.ScreenUpdating = True
    
    End Sub
    I hope that helps.
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  3. #3
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Macro - Copy and Paste to a Specific Row based on the input in a cell

    I added a line that will delete the rows in column B below B2, so that if you go from 50 to 25 you don't keep the lines below 25. I also got rid of most of the selections because it's best not to use them in my experience.

  4. #4
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Macro - Copy and Paste to a Specific Row based on the input in a cell

    This is all the code you need

    Sub Copy_Paste()
    Dval = Range("D1").Value
    
    Range("B2:B" & Dval).FormulaR1C1 = "=VLOOKUP(RC1,Data!C1:C2,2,FALSE)"
    
    End Sub

  5. #5
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    860

    Re: Macro - Copy and Paste to a Specific Row based on the input in a cell

    Or:
    Sub Copy_Paste()
    With Sheets("forumlas")
     If .Range("B2") > 0 Then
       .Columns(2).SpecialCells(-4123).Offset(1).ClearContents
      End If
      .Range("B2").Resize(.Range("D1") - 1).FormulaR1C1 = "=VLOOKUP(RC1,Data!C1:C2,2,FALSE)"
     End With
    End Sub
    Harry.

  6. #6
    Registered User
    Join Date
    10-26-2010
    Location
    USA
    MS-Off Ver
    Microsoft Office 2010
    Posts
    32

    Re: Macro - Copy and Paste to a Specific Row based on the input in a cell

    thanks for the help!

+ 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