+ Reply to Thread
Results 1 to 5 of 5

Thread: Copying a row and pasting the same below it with just formulas

  1. #1
    Registered User
    Join Date
    02-12-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Exclamation Copying a row and pasting the same below it with just formulas

    Hello!

    First of all, this really is an amazing resource!!

    Now, to my query. Any help will be much appreciated. I have attached the file. The row being copied is row "X" for both buttons

    I have 2 buttons in the same worksheet to copy a row and insert the
    copied row below it. I have this macro running for 2 different rows in the worksheet, assigned to the respective 2 buttons. See my code below.

    ______________________________________________________

    Private Sub CommandButton1_Click()
        Range("$B$7:$L$7").Select
        Selection.Copy
        Selection.Insert Shift:=xlDown
    End Sub
    
    Private Sub CommandButton2_Click()
        Range("$B$12:$L$12").Select
        Selection.Copy
        Selection.Insert Shift:=xlDown
    End Sub
    ________________________________________________________

    The problem is:

    1) I want just the formulas/formatting to be pasted, and not the
    entered values.
    2) And more importantly, if I use Button 1, then row 7 is copied and the copied row is added below row 7 and the rows move down. But then, for Button 2, row 12 is different....now as it has moved down (it has become 13, but the macro for button 2 is still copying row 12), if you understand? How do I keep it fixed that it always copies the contents of row 12 even if a row is added above and the rows move down, making row 12 into 13 and so on.

    Thanks again,

    Shivam
    Attached Files Attached Files
    Last edited by shivams22; 02-13-2010 at 08:34 PM. Reason: Simplification and meeting Forum rules

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: Copying a row and pasting the same below it with just formulas

    Hi Shivams, welcome to the forum. This forum is a great resource, but certain rules are strictly enforced, rules you agreed to just now when you joined.

    Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to edit that post above and put code tags around that code you used.

    The tags are demonstrated in my signature, your VBA code goes between them.

    Fix that post above, and consider using the PAPERCLIP icon (GO ADVANCED) to upload your workbook so we can look and see if we can spot another way do what you want. Highlight any pertinent cells in the workbook to draw our attention.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-12-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copying a row and pasting the same below it with just formulas

    Sorry JB, did as asked. Have simplified query and added attachment.

    Thanks very much!!

    Shivam

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: Copying a row and pasting the same below it with just formulas

    See, once we look at the sheet we can spot a "fixed feature" of your worksheet so we just find that "fixed position", then copy the row which is always a fixed distance away.
    Private Sub CommandButton1_Click()
    Dim rFind As Range
    Set rFind = Cells.Find(What:="TRADED AWAY", After:=[A1], LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
    
        With Range("B" & rFind.Row + 2 & ":L" & rFind.Row + 2)
            .Copy
            .Insert Shift:=xlDown
            Application.CutCopyMode = False
        End With
    Set rFind = Nothing
    End Sub
    
    Private Sub CommandButton2_Click()
    Dim rFind As Range
    Set rFind = Cells.Find(What:="RECEIVED IN TRADE", After:=[A1], LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
            
        With Range("B" & rFind.Row + 2 & ":L" & rFind.Row + 2)
            .Copy
            .Insert Shift:=xlDown
            Application.CutCopyMode = False
        End With
    Set rFind = Nothing
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    02-12-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copying a row and pasting the same below it with just formulas

    Thanks a lot! Works perfect!

+ 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.2.0