Consulting

Results 1 to 12 of 12

Thread: Solved: VBA Copy

  1. #1
    Banned VBAX Regular
    Joined
    Jul 2011
    Posts
    6
    Location

    Solved: VBA Copy

    Hi,

    I need to make a macro that cuts range ("C1:E57") and pastes it to ("Sheet1") in the active cell and then moves the active cell one place to the right so that the next time the macro is run, the data that is in ("C1:E57") can be pasted next to the last set of data in ("Sheet1").

    I am a complete beginner at macro but I had a go at it:

    Sub NewYear()
    '
    ' NewYear Macro
    '
    ' Keyboard Shortcut: Ctrl+n
    '

    Range("C1:E57").Select
    Selection.Copy
    Sheets("Sheet1").Select
    Offset(0, 1).Select.ActiveSheet.Paste

    End Sub

    This (of course) did not work but I have no idea what to try now!

    Please help me!

    Thanks and regards
    08mcrisp

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    example workbook please?
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    Banned VBAX Regular
    Joined
    Jul 2011
    Posts
    6
    Location
    Sorry!

    What does that mean?

    Apologies for my idiocy!

    08mcrisp

  4. #4
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    hahaha no problem, can you attach a dummy of your workbook so i can see what you are trying to do?
    ------------------------------------------------
    Happy Coding my friends

  5. #5
    Banned VBAX Regular
    Joined
    Jul 2011
    Posts
    6
    Location
    Here it is.

    I need to copy the cells that I specified earlier to sheet1 and then each time the macro is run, copy the new set of data in those cells next to the old set that is in sheet1.

    Just thought if I rephrased my query it might make more sense.

    Thanks for helping

    Regards
    08mcrisp
    Attached Files Attached Files

  6. #6
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location

    Red face

    [vba]Sub moveColumns()
    ActiveWorkbook.Sheets("Results").Activate
    Range("A1").Activate
    Dim cell As Range
    Dim destCell As String
    For Each cell In Range("A2:AZ2")
    If cell.Value = "" Then
    destCell = cell.Offset(-1, 0).Address
    Exit For
    End If
    Next cell
    ActiveWorkbook.Sheets("Sales").Activate
    Range("A1").Activate
    Range("C1:E57").Select
    Selection.Copy
    ActiveWorkbook.Sheets("Results").Activate
    Range(destCell).Activate
    ActiveSheet.Paste
    End Sub
    [/vba]

    works just fine for me
    Attached Files Attached Files
    ------------------------------------------------
    Happy Coding my friends

  7. #7
    Banned VBAX Regular
    Joined
    Jul 2011
    Posts
    6
    Location
    Thank you! That worked amazingly! You are a legend!!!!!!!

    Brilliant!!
    I can't thank you enough!!!


    08mcrisp

  8. #8
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    geez...how dare you make a black man blush? Just mark it as solved and pass it on!
    ------------------------------------------------
    Happy Coding my friends

  9. #9
    Banned VBAX Regular
    Joined
    Jul 2011
    Posts
    6
    Location
    How do I mark it as solved?

  10. #10
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    Top of the thread > Thread Tools > Marked Solved
    ------------------------------------------------
    Happy Coding my friends

  11. #11
    Banned VBAX Regular
    Joined
    Jul 2011
    Posts
    6
    Location
    I still can't find it!!

  12. #12
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    open with ie, if not already.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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