+ Reply to Thread
Results 1 to 9 of 9

Copy/Pasting Macro Function

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-11-2009
    Location
    Montclair, NJ
    MS-Off Ver
    Excel 365
    Posts
    236

    Copy/Pasting Macro Function

    Hey,

    I'm working on a quality control project (for products with Model #'s "1098", "1190", & "1220") for the company I work for and I'm having an issue with a macro.

    I have data coming from worksheet "Sheet1" AB6:AB21, that's getting "sent" to worksheets "1098", "1190", & "1220" E86:E101, and "Sheet1" AC6:AC21 -> worksheets in E151:E166

    In "Sheet1" cell F4, you enter the Model # ("1098" "1190" "1220"). I'd like this data above to ONLY go to the corresponding worksheet as cell F4 and not ALL model # worksheets. Is there a way that I can do this?

    Thank you for your time,
    Bob
    Attached Files Attached Files
    Last edited by sighlent1; 02-22-2010 at 10:47 AM. Reason: Solved

  2. #2
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Copy/Pasting Macro Function

    Hello, I have added macros to your worksheet to do this.
    1) Open your file & SaveAs to NEW TEST file. Open my attachment.
    2) Go to VB Editor. Double-click on the Sheet1 Module of my attachment. In the Code window, you will see new code (two procedures: Worksheet_Change and Update_Model_Value).
    3) Swipe over all of this text with your mouse (highlite EVERYTHING in blue, top to bottom). Copy to PC buffer (Ctrl+C).
    4) In VB Editor, DOUBLE-Click on Sheet1 of your NEW TEST file. The code window here should be blank. Plant cursor in code window and paste clipboard here (Ctrl+V).
    5) Save file.
    6) Now you need to build NINE (9) different RANGE NAMES in your TEST file as follows:
    6a) Go to F4 (sheet1), then type "Model_Cell" (w/o quotes) in Range Name field and hit enter.
    6b) Select cell AB6-AB21, sheet1. Type "MinData_Source" in Range Name field, enter.
    6c) Select cell AC6-AC21, sheet1. Type "MaxData_Source" in Range Name field, enter.
    6d) Select cell E86-E101, sheet1098. Type "MinData_Trgt1098" in Range Name field, enter.
    6e) Select cell E151-E166, sheet1098. Type "MaxData_Trgt1098" in Range Name field, enter.
    6f & 6g) Ditto for sheet 1190 typing "..._Trgt1190"
    6h & 6i) Ditto for sheet 1220 typing "..._Trgt1220"
    7) Save file again. It should work for you at this point.
    8) This macro will execute automatically whenever you change value in F4 of sheet1. Alternatively, you could assign a Shortcut Key to the Macro (such as C+S+M) to drive the "copy" macro. But with the Worksheet_Change macro, you don't have to do this, as it will automatically see change and drive "copy" macro for you.
    9) Study code over & test out on TEST file. Make sure it does what you want. Change accordingly. Holler back if you get stomped on anything.
    ... Regards, sauerj
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    02-11-2009
    Location
    Montclair, NJ
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: Copy/Pasting Macro Function

    Hey, Thank you sooo much SauerJ

    I did have some problems with it though. When typing in "Sheet 1" Cell F4, I would get an error message. Any idea why that would happen?

    Once again, Thank you soooo much and I really appreciate your time,
    Bob
    Attached Files Attached Files
    Last edited by sighlent1; 02-09-2010 at 03:29 PM. Reason: Forgot Attachment

  4. #4
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Copy/Pasting Macro Function

    1) Glad to help ... the macro was failing because your Target Range Names had gotten corrupted (i.e. they had #REF in their references). You probably named everything OK, but then you might have moved or copied something which caused these 6 Range Names to loose their reference. I edited your copy and am sending it back to you (see attached).
    2) Range Names may sound like a hassle, but they are better than putting hard cell addresses in your code. If the latter, then every time you insert columns or rows, or move your referenced cells, the code must be manually adjusted (major pain!). With Range Names, if you are careful, typically they hold fast in staying with the appropriate cells.
    3) The Range Name editor in Excel is VERY lacking. If you want to manage Range Names, I HIGHLY recommend downloading the following "Name Manager": (http://www.jkp-ads.com/OfficeMarketPlaceNM-EN.asp). ... Regards, sauerj
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    02-11-2009
    Location
    Montclair, NJ
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: Copy/Pasting Macro Function

    Hey SauerJ,

    The attached file says "Cannot Run the Macro" when I click the "Record Data" button

    Any idea why that is happening?

    Thank you, and as always for your time as well
    Bob

  6. #6
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: Copy/Pasting Macro Function

    Bob, That's a wierd one! ... Sounds like you meant to attach a file, but don't see it. Edit last post or add new post to include attachment. ... sauerj

  7. #7
    Forum Contributor
    Join Date
    02-11-2009
    Location
    Montclair, NJ
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: Copy/Pasting Macro Function

    Hey Sauerj, I meant with the file in the last message you sent says "Cannot Run the Macro" when I click the "Record Data" button after adding in the values in worksheet "Sheet1"......here is the file with the values ready to be inserted right before clicking the "Record Data" button

    Any idea why this message would come up?

    Thank you,
    Bob
    Attached Files Attached Files

  8. #8
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile Re: Copy/Pasting Macro Function

    Bob, I apologize for my last post. I mis-read your previous post. When you said, "Record Data" button, I mis-read this as "Record Macro" button. So, I thought you were getting this message when you were trying to Record a new Macro. That's why I thought this was a real wierd one.
    Now that I see that you have a Macro Button on your worksheet labeled "Record Data", I now understand your issue. Sorry!
    Fortunately, this is an easy fix. Maybe you have figured it out already. If you RIGHT-CLICK on the "Record Data" button and select ASSIGN MACRO, you will see that the button has a macro assigned called #N/A. But, this is not a macro in the list of available macros to run. So, all you have to do is select which macro of the list of available macros you want to execute when you hit this button. I assume you want the "Sheet1.Update_Model_Value" macro. Once you have made this macro assignment, then it should work for you. ... Holler back if this doesn't fix it or if you have further issues. Take care, Joe.

  9. #9
    Forum Contributor
    Join Date
    02-11-2009
    Location
    Montclair, NJ
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: Copy/Pasting Macro Function

    Thank you JOE!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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