+ Reply to Thread
Results 1 to 36 of 36

After copying in Macro - come back to previous sheet

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Hi - I've changed the code below just to show you some options about this sort of thing; I do recommend though that you have a think about how your ranges are defined (static or dynamic) and you might be able to create a loop that does the same thing. I've made this as generic as I can to demonstrate and you can choose the most appropriate option for what you're doing ...
    Sub YourControlRoutine()
    Dim wshSource As Worksheet, wshTarget1 As Worksheet, wshTarget2 As Worksheet
    Dim strSourceRange1 As String, strSourceRange2 As String
        'your code to where you initiate the copy/paste, then ...
        
        'if these are static then just set them:
        strSourceRange1 = "A1:A5"
        strSourceRange2 = "C1:C5"
        '(... but if they aren't static, and (say) you select the ranges
        'before copying, then you could use just one variable (setting
        'it as the range is selected or the address is otherwise determined,
        'such as:
        'strSourceRange = Selection.Address).
        
        Set wshTarget1 = ActiveWorkbook.Worksheets(2)
        Set wshTarget2 = ActiveWorkbook.Worksheets(3)
        
        Set wshSource = ActiveWorkbook.Worksheets(1)
        
        Call MoveToMultipleSheets(wshSource, wshTarget1, wshTarget2, strSourceRange1)
        Call MoveToMultipleSheets(wshSource, wshTarget1, wshTarget2, strSourceRange2)
        
        'depending on what you're doing, you could call the other sub 4 times and
        'just pass in a source & one target each time, which would look like:
        'Call MoveToMultipleSheets(wshSource, wshTarget1, strSourceRange1)
        'Call MoveToMultipleSheets(wshSource, wshTarget2, strSourceRange1)
        'Call MoveToMultipleSheets(wshSource, wshTarget1, strSourceRange2)
        'Call MoveToMultipleSheets(wshSource, wshTarget2, strSourceRange2)
        
        ' etc etc etc ...
        
    End Sub
    
    Sub MoveToMultipleSheets(shtS As Worksheet, shtT1 As Worksheet, shtT2 As Worksheet, strAddress As String)
        shtS.Range(strAddress).Copy
        With shtS
            .Paste Destination:=shtT1.Range(strAddress)
            .Paste Destination:=shtT2.Range(strAddress)
        End With
        Application.CutCopyMode = False
    End Sub
    Hope that helps ... MM.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  2. #2
    Forum Contributor
    Join Date
    07-06-2008
    Location
    NC
    Posts
    149

    My File

    Here is an example:

    There are alot of combinations to copy each section into each section of another page. Altogther there are 5 sections that could be copied into any section of another page.

    I can write the code but it would be alot if this, then this.

    The last one is different that what I am used to (as I am not a programmer)

    I am trying to write and learn about real code as possible...seems to work better and can be easier changed. I could write a macro that woould work but it would take so long. I like your guys ideas. Here is an example file that i tried to make as simple as possible. I get an error when running with combining the paste parts.
    Attached Files Attached Files

+ 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. Macro to populate a cell and then execute another macro
    By andrewc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-29-2008, 02:19 PM
  2. macro to create a macro?
    By jojotherider in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2008, 08:34 PM
  3. Macro for copy/insert into expanding table
    By Soslowgt in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-06-2008, 07:24 PM
  4. How to splitt texts into words? (collecting word and compounds)
    By wali in forum Excel Programming / VBA / Macros
    Replies: 53
    Last Post: 02-03-2008, 04:06 AM
  5. Conditional formatting macro (highlight macro)
    By c991257 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2007, 02:46 PM

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