+ Reply to Thread
Results 1 to 7 of 7

Jump back and forth between two sheets to copy values

Hybrid View

ismafoot Jump back and forth between... 10-12-2018, 09:19 PM
alansidman Re: Jump back and forth... 10-12-2018, 10:39 PM
ismafoot Re: Jump back and forth... 10-12-2018, 11:09 PM
alansidman Re: Jump back and forth... 10-12-2018, 11:17 PM
ismafoot Re: Jump back and forth... 10-12-2018, 11:20 PM
alansidman Re: Jump back and forth... 10-12-2018, 11:37 PM
ismafoot Re: Jump back and forth... 10-13-2018, 08:40 AM
  1. #1
    Registered User
    Join Date
    05-24-2018
    Location
    Canada
    MS-Off Ver
    Windows 7
    Posts
    35

    Jump back and forth between two sheets to copy values

    Hello,

    I am having trouble in making this code work:

    Sub newsheet()
    'Allows the user to copy the active sheet and clear contents in columns payments and advances of each product.
        
        Application.ActiveWorkbook.ActiveSheet.Select
        Application.ActiveWorkbook.ActiveSheet.Copy After:=ActiveSheet
        Range("C8:D38,H8:I38,M8:N38,R8:S38,W8:X38,AB8:AC38,AG8:AH38,AL8:AM38").Select
        Selection.ClearContents
        ActiveWorkbook.ActiveSheet.Range("A1").Select
        
        
        Dim wks As Worksheet
        Dim rng As Range
        
        Set wks = Application.ActiveWorkbook.ActiveSheet.Previous
        Set rng = wks.Range("E39")
        ' copies ending balance of previous sheet to beg. balance of newly created sheet.
        
        Do While Not IsEmpty(rng)
            rng.Copy
        
            Application.ActiveWorkbook.Worksheets(wks.Index + 1).ActiveCell.Offset(-32, 0).PasteSpecial xlPasteValues
        
            Set rng = rng.Offset(0, 4).Select
        Loop 'Loops back through the previous sheet to until it doesnt find any product anymore.
        
    End Sub
    The error message (Object doesnt support this propety or method) occurs at the end of the code:

    Application.ActiveWorkbook.Worksheets(wks.Index + 1).ActiveCell.Offset(-32, 0).PasteSpecial xlPasteValues
    Last edited by jeffreybrown; 10-12-2018 at 09:22 PM. Reason: Please use code tags!

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,698

    Re: Jump back and forth between two sheets to copy values

    Without seeing your actual workbook and being able to test, this is my best guess at this time. You have already defined wks as a worksheet, so you do not need to name it as part of the worksheets in the workbook. It is already a variable.


    Application.ActiveWorkbook.wks.Index + 1.ActiveCell.Offset(-32, 0).PasteSpecial xlPasteValues
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    05-24-2018
    Location
    Canada
    MS-Off Ver
    Windows 7
    Posts
    35

    Re: Jump back and forth between two sheets to copy values

    I have a syntax error.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,698

    Re: Jump back and forth between two sheets to copy values

    Like I said, without seeing your workbook or a representative sample of it, it is difficult to determine what the issue is and how to fix it Also, it would be very helpful if you explained what you are trying to do instead of us trying to interpret what your non-working code is meant to do. A simple detailed explanation will go a long way to solving this.
    Last edited by alansidman; 10-12-2018 at 11:20 PM.

  5. #5
    Registered User
    Join Date
    05-24-2018
    Location
    Canada
    MS-Off Ver
    Windows 7
    Posts
    35

    Re: Jump back and forth between two sheets to copy values

    Quote Originally Posted by alansidman View Post
    Like I said, without seeing your workbook or a representative sample of it, it is difficult to determine what the issue is and how to fix it
    there you go Thank you!
    Attached Files Attached Files

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,698

    Re: Jump back and forth between two sheets to copy values

    In your line of code, excel is looking for a destination cell to paste into. You have indicated ActiveCell, however, it does not appear that you have selected an active cell in the destination. ActiveCell does not work in this situation. Is there a specific destination cell you are looking to populate. Probably need to set it up as a variable.

    It would also help if there was dummy data to work with instead of blank cells. And as I indicated earlier, a brief explanation would go a long way.

  7. #7
    Registered User
    Join Date
    05-24-2018
    Location
    Canada
    MS-Off Ver
    Windows 7
    Posts
    35

    Re: Jump back and forth between two sheets to copy values

    I am trying to carry over the ending balance (copied sheet) to the new sheet (pasted sheet) in the beginning balance with its respective product#.
    I got it with this code:
        
    Dim wks As Worksheet
        Dim rng As Range
        Dim rng2 As Range
        Set wks = Application.ActiveWorkbook.ActiveSheet.Previous
        Set rng = wks.Range("E39")
        Set rng2 = Application.ActiveWorkbook.ActiveSheet.Range("E7")
        ' copies ending balance of previous sheet to beg. balance of newly created sheet.
        
        Do While Not IsEmpty(rng)
            rng.Copy
            rng2.PasteSpecial xlPasteValues
            
            Set rng = rng.Offset(0, 4)
            Set rng2 = rng2.Offset(0, 4)
        Loop 'Loops back through the previous sheet until it doesnt find any product anymore.
        
    End Sub
    Last edited by alansidman; 10-13-2018 at 11:09 AM. Reason: enhanced code

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy a range, and then paste back the values only.
    By Angry Robot in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2017, 12:42 PM
  2. Replies: 5
    Last Post: 09-16-2014, 12:17 PM
  3. Jump back and forth between sheets
    By pigpen in forum Excel General
    Replies: 1
    Last Post: 09-05-2014, 01:47 PM
  4. Copy Cell Values in two Columns down x number of times then jump and copy some more.
    By scholly23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2014, 03:19 AM
  5. [SOLVED] Jump to a cell and back??
    By ladi100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-17-2013, 05:30 AM
  6. Need a Macro to Jump back to previous page
    By MD77614 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2012, 02:48 PM
  7. Closing sheets as I jump back to main sheet
    By dollydoodah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-14-2011, 09:45 AM

Tags for this Thread

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