+ Reply to Thread
Results 1 to 38 of 38

A formula to copy a row from one sheet to another if a certain number is entered in a cell

  1. #1
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    A formula to copy a row from one sheet to another if a certain number is entered in a cell

    Hello

    I need a formula that will copy a row on sheet 1 if the first cell on the row on sheet 2 includes the same number as a number at the start of a row on sheet 1.

    I know it probably sounds a bit wierd but i honestly don't know a better way to explain it.

    Below is an image of what both sheet 1 and sheet 2 look like. I'm basically going to be using sheet 2 as a short list for sheet 1 so i only need certain data to be copied across.

    Capture.PNG

    If anyone can help it would be much appreciated. If you need any more info please let me know
    Attached Files Attached Files
    Last edited by cores1805; 01-15-2016 at 09:52 AM. Reason: EDIT: Uploaded file

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Please post a file showing expected results as many of use cannot view an (PNG) image: nor can we work with it!

  3. #3
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Just uploaded my excel file. I've stripped all of the data out for obvious reasons.

  4. #4
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Bump.

    Could really use some help on this if anyone knows.

  5. #5
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    What is password ???????????????
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  6. #6
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Ah, forgot about the password, its nightingale and to edit the document its test.

  7. #7
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Try

    If Sheet 1 to Sheet2
    Then
    Sheet2
    B1=INDEX(sheet1!$B$2:$S$2500,MATCH(sheet2!$A2,sheet1!$A$2:$A$2500,0),MATCH(sheet2!B$1,sheet1!$B$1:$S$1,0)) and drag down & over the right side cells.

    If Sheet 2 to Sheet1
    Then
    Sheet1

    B1=INDEX(sheet2!$B$2:$S$2500,MATCH(sheet2!$A2,sheet2!$A$2:$A$2500,0),MATCH(sheet2!B$1,sheet2!$B$1:$S$1,0)) and drag down & over the right side cells.
    Last edited by shukla.ankur281190; 01-14-2016 at 07:10 AM.

  8. #8
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I just tried your suggestion and I get an error when I enter a number into column A on sheet 2 as seen below.

    ERROR.PNG

    I'm not very good with excel to be honest so it might be something simple but any help is appreciated.

  9. #9
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Are pasting it in VBA. It is a formula for Excel sheet. Paste it on worksheet not in VBA modules.

  10. #10
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I know I must sound like an idiot but I honestly don't know where to put this. I've never seen this format of formula before.

  11. #11
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I don't think that formula is what I'm looking for. I need the formula to identify if I entered a specific number in column A in sheet2 that matched a number on column A on sheet1. If it matches, i need it to copy the entire row which had the number on it from sheet1 to sheet2.

  12. #12
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Bump.

    I've been told that this cannot be done using formulas, not sure if its true. If anyone has a macro to do what i need, that would be great.

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Let me understand this:

    if you enter for example 6354 in column A of Sheet2, you want the data for that row in Sheet1 to be put in Sheet2?

  14. #14
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Yes, exactly.

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Will data be deleted from Sheet2?

    Or can we add a column in Sheet1 which indicates data needs to be moved to Sheet2 rather than entering a number in Sheet2?

    VLOOKUP will work but if the data in column A of Sheet2 is left blank i.e. deleted, will be left with a blank row,

  16. #16
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Once the data on sheet2 is completed and no longer a priority, it will be deleted since sheet2 is basically a priority list / short list. It would be preferred that we don't have to add anything to sheet1 but if there is no other way then we won't have much choice.

  17. #17
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    If there was a column in Sheet1 which had (for example) "A" (add to Sheet2) and "D" (delete) then it possible to make the listing in Sheet2 dynamic by checking Sheet1 for all records which have "A". As records are added/deleted (only need to check for "A" in reality) then the list in Sheet2 will expand/shrink accordingly.

    Equally, you do not need to enter data into Sheet2: everything would work from Sheet1.

    This is a fairly common way of addressing your need.

  18. #18
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    So, if i was to do this, how would i go about doing it? Do you have a formula / macro that would work for this? I'm honestly not great with excel so i would appreciate the help if you know.

    Like i said, it would be preferable if i didn't have to add further columns to sheet1 but if it has to be done then we have no choice.

  19. #19
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    With "y" in column T of sheet1

    put this in A2 of Sheet2

    =IFERROR(INDEX(sheet1!B$2:B$100,SMALL(IF(sheet1!$T$2:$T$100="y",ROW($A$2:$A$10)-ROW($A$2)+1,""),ROWS($A$2:$A2))),"")

    Enter with Ctrl+Shift+Enter (array formula)

    Copy across and down columns.


    Change range (100) to suit as many rows as you think is your likely maximum: don't do more than neessary

  20. #20
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Non-array formula (less resource hungry)


    =IFERROR(INDEX(sheet1!A$2:A$100,AGGREGATE(15,6,ROW($A$1:$A$100)/(sheet1!$T$2:$T$100="y"),ROW($A1))),"")

  21. #21
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I tried what you suggested but it doesn't seem to be working. Its entirely possible I'm doing something wrong but I'm not sure.

  22. #22
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    As an additional request, we are thinking of setting up a 3rd sheet so is it a possibility to make it so if you enter a 2 in column T it would copy it to sheet2 and if you enter a 3 it would copy it to sheet3?

  23. #23
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    To answer your additional request:

    Put the formula in Sheet2 and change the test to

    =IFERROR(INDEX(sheet1!A$2:A$100,AGGREGATE(15,6,ROW($A$1:$A$100)/(sheet1!$T$2:$T$100="2"),ROW($A1))),"")

    Put the formula in Sheet3 and change the test to

    =IFERROR(INDEX(sheet1!A$2:A$100,AGGREGATE(15,6,ROW($A$1:$A$100)/(sheet1!$T$2:$T$100="3"),ROW($A1))),"")

    re the "not working":

    Both formulae were tested on your posted file and worked fine: did you do any changes to the formula?

  24. #24
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Quote Originally Posted by JohnTopley View Post
    Non-array formula (less resource hungry)


    =IFERROR(INDEX(sheet1!A$2:A$100,AGGREGATE(15,6,ROW($A$1:$A$100)/(sheet1!$T$2:$T$100="y"),ROW($A1))),"")
    The equivalent array formula is slightly faster to calculate.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  25. #25
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Thanks for the additional formulas

    I'm not sure what I'm doing wrong, i've tried both the array and non-array formulas that you sent and I can't get them for work.

    Just to go through the steps of what I'm doing:
    1. enter number 2 into column T on sheet1
    2. paste formula into A2 on sheet2 with Ctrl + Shift + Enter
    3. Drag the formula down column A.

    Not sure what im doing wrong.

  26. #26
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Drag ACROSS rows as well as down columns

  27. #27
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    @Tony,
    Well - when to "array" and not to "array": that is the question!!!

    I take it generally the array formulae are faster than AGGREGATE or just this (specific?) case?

  28. #28
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I've dragged both across and down and still nothing : /

  29. #29
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I can only suggest you post a small sample from the file which is causing the problem.

  30. #30
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I've replaced the excel file attachment on the original post with the file I've added the formula to. Can you take a look and possibly see where I'm going wrong?

  31. #31
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Remove the quotes from round the 2

    =IFERROR(INDEX(sheet1!A$2:A$100,AGGREGATE(15,6,ROW($A$1:$A$100)/(sheet1!$T$2:$T$100=2),ROW($A1))),"")

    The "2" is treated as TEXT whereas the value in T is a number. "Mea Culpa" as I did not do that in the formula in posted so my apologies. You did nothing wrong!

    Did you see the post from Tony Valko (Forum Guru) who said the array formula is actually slightly faster so you may want to use that instead,

  32. #32
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Well, that seems to have done it! Thanks very much for your help. Time to move this over to the original file and hope everything works well. Cheers

  33. #33
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Again, my apologies: "schoolboy" error. Thank you for your patience.

    If all is OK, could you mark the thread as solved ("Thread Tools" at top of first post)

  34. #34
    Registered User
    Join Date
    01-13-2016
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    18

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    I'm going to get everything into the original sheet, check everything works ok there and then I'll change it to solved if it all works.

  35. #35
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Yes, that's OK.

  36. #36
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    Quote Originally Posted by JohnTopley View Post
    I take it generally the array formulae are faster than AGGREGATE or just this (specific?) case?
    The more criteria there is, the slower it will be to calculate compared to the equivalent array formula.

    People think that just because you don't have to array enter the AGGREGATE function it must be better. Sometimes, sometimes not.

    Just the basic function (without lots of criteria) is pretty good...

    Data Range
    A
    B
    C
    1
    Value
    Max
    2
    92
    96
    3
    20
    4
    text
    5
    58
    6
    44
    7
    #N/A
    8
    96
    9
    95
    10
    2
    11
    ------
    ------
    ------


    =AGGREGATE(14,6,A2:A10,1)

  37. #37
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    @tony,
    Thank you for the explanation.

    I tried a non-scientific test (i.e, no clock timings) on a recent posting with 66,000+ rows and the INDEX version did seem to run quicker.

  38. #38
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: A formula to copy a row from one sheet to another if a certain number is entered in a

    ______

+ 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 Paste a Range of Values from a Different Sheet Based on Value Entered in Cell
    By hamidxa in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-13-2015, 04:53 PM
  2. Copy rows to new sheet if value of cell entered greater than 1
    By shahzzy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-19-2015, 12:09 PM
  3. Replies: 4
    Last Post: 04-18-2013, 03:07 PM
  4. Replies: 1
    Last Post: 04-18-2013, 02:51 PM
  5. Copy rows to new sheet if value of cell entered greater than 1
    By larryluv1 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-04-2013, 02:55 PM
  6. VBA copy sheet 1 to a new sheet when data is entered in a certain cell
    By dustinshepard in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2012, 11:50 PM
  7. Copy row from Sheet 1 to Sheet 2 when data entered in cell F
    By tony0710 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-12-2011, 02:39 PM

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