+ Reply to Thread
Results 1 to 7 of 7

Macro to insert data in specific cell based on criteria

  1. #1
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Macro to insert data in specific cell based on criteria

    I'm re-posting this in the hope that someone can help.

    In the example enclosed I'd like to add some code to a command button on Sheet 2 so that the data on Sheet 1 cell M27 is entered in to cell C12 on Sheet 2 because of the criteria set out in Sheet 1 cells H2 (Week) and M2 (Identifier) - the data is inserted in to the relevant point on the matrix in Sheet 2.

    Any help appreciated.

    Thanks Steve
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Macro to insert data in specific cell based on criteria

    Hi SAsplin,
    If you were to turn on the Record Macro and simply copy and paste like you suggest, you would get the following macro.
    Please Login or Register  to view this content.
    Then edit your command button to fire this macro when you clicked on it and you would be done.

    Is that all you wanted?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Macro to insert data in specific cell based on criteria

    Thanks for the reply -

    That would simply copy and paste the value from cell M27 on sheet 1 to cell C12 on Sheet 2.

    Sheet 1 will constantly change - the unique identifier, the week and the value in M27 will change.

    I'd like the macro to look up the week number (H2) and the identifier (M2) and insert value in cell M27 into the relevent place in the matrix on Sheet 2 - weeks are on row 6 and identifiers in column A.

    Cheers

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Macro to insert data in specific cell based on criteria

    Hi,
    I get it now. Try calling this code from you button click,
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Macro to insert data in specific cell based on criteria

    Quote Originally Posted by MarvinP View Post
    Hi,
    I get it now. Try calling this code from you button click,
    Please Login or Register  to view this content.
    I've added this code to the command button and it comes back with the following runtime error 1004:

    'Unable to get the Match property of the WorksheetFunction class'

  6. #6
    Forum Contributor
    Join Date
    08-17-2009
    Location
    West Midlands
    MS-Off Ver
    Excel 2016
    Posts
    213

    Re: Macro to insert data in specific cell based on criteria

    Ok. I know I'm a bit of a thickie with this but...

    The above code works perfectly if the command button is on Sheet1 but it's on Sheet2. How do I change the above code for this?

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to insert data in specific cell based on criteria

    HI, SAsplin, your task can be easily solved with formula or with code, please check attachment
    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)

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