+ Reply to Thread
Results 1 to 12 of 12

Need to create a button that can copy cells, create a new sheet and then paste there

Hybrid View

torontoguy Need to create a button that... 01-14-2009, 09:18 AM
VBA Noob Maybe ... 01-14-2009, 09:29 AM
torontoguy ive got Sub... 01-14-2009, 09:44 AM
VBA Noob Don't follow. You are now... 01-14-2009, 10:02 AM
torontoguy is that what you meant? 01-14-2009, 09:57 AM
torontoguy No sorry. What Im trying to... 01-14-2009, 10:05 AM
VBA Noob Try Dim LastRow As Long... 01-14-2009, 10:23 AM
torontoguy that sort of worked, thanks... 01-14-2009, 10:27 AM
VBA Noob Try attached example 01-14-2009, 10:54 AM
torontoguy yes this seems to work ... 01-14-2009, 11:10 AM
VBA Noob Need to change the resize as... 01-14-2009, 11:16 AM
torontoguy Excellent. Thanks. 01-14-2009, 11:26 AM
  1. #1
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72

    Need to create a button that can copy cells, create a new sheet and then paste there

    So I've got Sheet 1 with say

    ____A___B___C
    1___m___i___c
    2___r___o___s
    3___o___f___t

    I would like to create a button that can create a new sheet and paste A1 to C3 at the same location on the new sheet

    and I need this to create a new sheet and do that everytime the button is pressed

    can someone help me with this?




    I've tried creating a shape and assigning a recorded macro to it where i did this:
    1. create a new sheet (this part worked)
    2. copy data (this worked)
    3. pasted onto new sheet (did NOT work, instead it kept pasting onto the same sheet and 2 lines below the older version)
    Last edited by torontoguy; 01-30-2009 at 11:43 AM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

     Sheets("Sheet1").Copy After:=Sheets(Sheets.Count)
    Change Sheet1 to the sheet to copy

    you can add a button from the forms toolbar and right click > assign macro

    http://www.bettersolutions.com/excel...B215612321.htm

    Edit

    or

    Dim NewSht As Worksheet
    Set NewSht = Sheets.Add
        NewSht.Move After:=Sheets(Sheets.Count)
    
        With Sheets("Sheet1")
            .Range("A1").CurrentRegion.Copy Destination:=NewSht.Range("A1")
        End With
    VBA Noob
    Last edited by VBA Noob; 01-14-2009 at 09:36 AM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72
    ive got

    Sub Rectangle1_Click()
    '
    ' Rectangle1_Click Macro
    '
    
    '
        Sheets.Add After:=Sheets(Sheets.Count)
        Sheets("Risk Assessment Outline").Select
        Range("B3:K7").Select
        Selection.Copy
        Sheets("Sheet4").Select
        Range("C3").Select
        Sheets("Sheet4").Select
        Range("B3").Select
        ActiveSheet.Paste
        Range("F10").Select
    End Sub
    also, another question is... can i create a button that copies data and pastes it directly under

    say I copy A1 to B10

    can I create a macro that will copy that and paste it at like... D1 to E10 the next time
    and then the next time I click, it will create it at G1 to H10 (keeps going but leaves a space in between them)
    Last edited by torontoguy; 01-14-2009 at 09:57 AM.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    say I copy A1 to B10

    can I create a macro that will copy that and paste it at like... D1 to E10 the next time
    and then the next time I click, it will create it at G1 to H10 (keeps going but leaves a space in between them)
    Don't follow. You are now saying copy from Sheet A to Static Sheet B?

  5. #5
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72
    is that what you meant?

  6. #6
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72
    No sorry. What Im trying to do now is in just 1 Sheet

    Copy rows A and B to rows C and D with the click of a button
    and everytime the button is clicked, copy rows A and B in the next available set of rows (next one in this case would be E and F)

    (we can do spacing later because I believe that's the easier part)

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try

    Dim LastRow As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Rows("1:2").Copy Destination:=Rows(LastRow + 1).Resize(2)
    or with the extra row

    Dim LastRow As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Rows("1:2").Copy Destination:=Rows(LastRow + 2).Resize(2)

  8. #8
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72
    that sort of worked, thanks for that
    but this is the problem now:

    on my first click, it created rows A and B on rows C and D
    however, when I clicked multiple times after, it kept creating it on rows C and D

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try attached example
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72
    yes

    this seems to work

    Option Explicit
    
    Sub CopyRows()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    Rows("1:2").Copy Destination:=Rows(LastRow + 2).Resize(2)
    
    End Sub
    if I would like to expand this to say copy the first 100 rows, would I just change

    Rows("1:2").Copy Destination:=Rows(LastRow + 2).Resize(2)
    to

    Rows("1:100").Copy Destination:=Rows(LastRow + 2).Resize(2)

  11. #11
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Need to change the resize as well

    Dim LastRow As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Rows("1:100").Copy Destination:=Rows(LastRow + 2).Resize(100)

  12. #12
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72
    Excellent. Thanks.

+ 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