CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Copy and Paste

  1. #1
    Join Date
    Jan 2007
    Posts
    6

    Copy and Paste

    Hello,

    I am creating an invoicing entry in one sheet and keeping those entry to another sheet as a master record using excel. I am doing this a repetitive action everyday.

    What I understand I can record the activities in macro and possible to modify the code to a more feasible and reliable however I am newbie in visual basic programming. What I am trying to get through, how to make a code pasting the invoicing entry after the last row in the master worksheet

  2. #2
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    Re: Copy and Paste

    U can copy some range from one sheet and paster after the last used cell of a column like this

    Code:
    Sub Macro3()
    '
    ' Macro3 Macro
    '
    '
    
    '
        Sheets("Sheet1").Select // Select ur Source Sheet
        Range("A1").Select         // Select First Cell of Column A 
        Range(Selection, Selection.End(xlDown)).Select  // Select complete column till end
        Selection.Copy  // Copy Values
        Sheets("Sheet2").Select  // Select Sheet2 ( Destination Sheet)
        Dim nCount As Integer
        nCount = Sheets("Sheet2").UsedRange.CurrentRegion.Rows.Count // Get Last used Row on Sheet2
        Cells(nCount + 1, 1).Select // Select Last cell of Column A
        ActiveSheet.Paste  // Paster Values
        
    End Sub
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  3. #3
    Join Date
    Jan 2007
    Posts
    6

    Smile Re: Copy and Paste

    Syntax error on this portion.

    nCount = Sheets("Sheet2").UsedRange.CurrentRegion.Rows.Count // Get Last used Row on Sheet2

  4. #4
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    Re: Copy and Paste

    I have checked this code , no syntax error
    I have modified comments in this code plz try this.

    Code:
    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 1/31/2007 by AAA
    '
        Sheets("Sheet1").Select ' Select ur Source Sheet
        Range("A1").Select       '   Select First Cell of Column A
        Range(Selection, Selection.End(xlDown)).Select '  Select complete column till end
        Selection.Copy  ' Copy Values
        Sheets("Sheet2").Select  ' Select Sheet2 ( Destination Sheet)
        Dim nCount As Integer
        nCount = Sheets("Sheet2").UsedRange.CurrentRegion.Rows.Count ' Get Last used Row on Sheet2
        Cells(nCount + 1, 1).Select '  Select Last cell of Column A
        ActiveSheet.Paste  ' Paster Values
    
    '
    End Sub
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  5. #5
    Join Date
    Jan 2007
    Posts
    6

    Thumbs up Re: Copy and Paste

    Great!!!! The code is working perfectly. Now I can sit back and relax.

    Thank you so much.

    John

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured