+ Reply to Thread
Results 1 to 36 of 36

After copying in Macro - come back to previous sheet

Hybrid View

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

    How about this

    I still need to look up how to use CASE properly,

    but besides that, this is something I was trying to do. Of course it does not work yet? Suggestions??
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Here's how your case should look, but I don't understand what you mean by "for each selection" ... each selection of what?

        Select Case Range("N5")
            Case 1 To 5
                Set Ws = Worksheets("Sheet2")
            Case 2, 8, 14
                Set Rng2 = Range("C36:C41")
        End Select
    
        Select Case Range("Q5").Value
            Case 1
                Set Rng1 = Range("C28:C33")
        End Select
    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.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Not sure if this is what you want, sheet references might need changing, but I have attempted to change your code to use Select Case

    Sub AutoShape1_Click()
    
        With Application
            .ScreenUpdating = False
    
            Dim Ws As Worksheet
            Dim Rng1 As Range
            Dim Rng2 As Range
    
    
            Select Case Range("N5").Value
                Case 1 To 5: Set Ws = Worksheet("Sheet2")
                Case 2, 8, 14: Set Rng2 = Range("C36:C41")
                Case Else: MsgBox "Incorrect entry"
            End Select
    
            Select Case Range("Q5").Value
                Case 1: Set Rng1 = Range("C28:C33")
                Case Else: MsgBox "Incorrect entry"
            End Select
    
            'The next part would do the copying and pasting depending upon what I selected
    
            Rng1.Copy Destination:=Rng2
            .ScreenUpdating = False
            .CutCopyMode = False
        End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

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

    Close

    I think we are close.

    the one line
    HTML Code: 
    gives me an error
    if I do this:
    HTML Code: 
    It works with assigning a value to the rng2

  5. #5
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Rng1.Copy Destination:=Ws.Range("C28:C33")
    Versus:
    Rng1.Copy Destination:=Rng2
    The 2nd one should be
    Rng1.Copy Destination:=Ws.Rng2
    ... so it goes to the right sheet, otherwise you're cutting & pasting to the same place in the active sheet ..

    Or - since you've got different variables for the same range address (as far as I can tell from the snippet) then set Rng2 explicitly such as:
    Set Rng2=Ws.Range("C28:C33")
    And then you can:
    Rng1.Copy Destination:=Rng2
    Hope that helps

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

    get error

    When I do change to this:
    HTML Code: 
    I get the error: Method or data member not found. Is it assinged or DIm correctly??

    I also thought that would work.

  7. #7
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Ah ha! I think it may be because Rng2 is only set if a particular case condition is met ... When stepping through, hover over Rng2 and if it says "Nothing", then that's your problem

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

    More Help

    I was looking for more examples as how to fix my macro but I am still in need of more expertise.

    I attached my last go around. I did manage to change another macro by using variables. Yeally shortens the code alot! So I am learning.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I have simplified this, it shoulod give you an idea what you need to do.
    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