+ Reply to Thread
Results 1 to 15 of 15

Copying specific cells based on cell value "P" or "O" to sht1 or sht2

  1. #1
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    I need some help copying cells f10,h10,f13,h13,j13,f16,h16,j16 as well as f20:k42 if cells are not blanks to two different sheets. To sheet1 if column k20:k42 value is "P", if value is "O" then copy all cells to sheet2 in rows. Always copy to next blank row. I have done a lot of searching and formulating to no avail
    Can you please help?

  2. #2
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    What you're requesting sounds doable, but more details would be helpful. Can you clarify a few of the particulars? What sheet is the data being copied from? When the data is copied to sheet 1 or 2, what's the arrangement? Does F10 go to A1 (or column A of the next empty row), H10 to A2, etc? The most useful resource would be a sample workbook (Use Go Advanced > Manage Attachments) that demonstrates how your info looks and how you want it to look in the end.

  3. #3
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    Hi,

    What i am tying to achieve is if column "K" in Input sheet value is "p" then copy the record to sheet5 but if column "K" value is "o" then copy to sheet6

    for example if k20 value is "P" then
    copying would entail copying cells f10 to j16 as well as for example f20:j20 to sheet5 but if
    for example if k20 value is "O" then copy the above to sheet 6

    this would repeat for each record, next record which copies would be f10 to j16 again but cells this time will be f21:j21 and so on to cells
    f42:j42. seperating data

    Can you help?

    Thanks
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    The destinations still aren't clear - if I'm copying f10 to J16 and f20:j20 to sheet 5 (for example), what cells do they land in? I took a guess, and just arrayed your information across the row. Try the procedure below out and see if it works. You'll need to put your headings for sheets 5 and 6 in Row 1 and you'll need to tweak the formats on sheets 5 and 6 to your liking, but it should cleanly transfer your data across the rows. I tried to leave the structure of the VBA pretty clear so that you could make modifications as necessary. Let me know how it goes.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    I have checked the formula it is working well, but i need to start the data copying on sheet5 and sheet from from cell A6.

    Also is there a way of moving data from sheet5 to a new sheet Cancel, for example whichever rows a user selects and clicks cancel macro, the data moves in to Cancel sheet A6 until lastrow

  6. #6
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    Is there any data in Row 5 of Sheets 5 or 6?

  7. #7
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    No data in row 5 of both sheets, need space at the top for headings buttons etc

  8. #8
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    The version below should start at A6. As to your second request, how do you envision the selection occurring? Is the user selecting the entirety of the data he/she wants moved to the Cancel page (so basically a cut/paste)? Would you prefer an input box asking for the first and last row to be moved, then have the procedure move everything in between?

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    Thanks cantosh for the help, I have managed the cancel procedure by using selection.copy then cut/ paste method and then selection.delete

  10. #10
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    My pleasure, I'm glad you got it working

  11. #11
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    can someone help me with this scenario, i have a macro Cancel on sheet5, once a row is selected and the macro is clicked it should transfer the selected rows to the cancel sheet in the next available empty row till last row and delete from sheet5. both sheets are protected and must stay protected. once the macro runs i get error
    1004: pastespecial method of range class failed. this is my code so far:

    Sub Cancel()
    Sheets("Sheet5").Activate
    ActiveSheet.Unprotect Password:="lemon1"
    Cells.Select
    ' unlock all the cells
    Selection.Locked = False
    Selection.Copy
    Sheets("CANCEL").Activate
    ActiveSheet.Unprotect Password:="lemon1"
    Cells.Select
    ' unlock all the cells
    Selection.Locked = False
    ActiveSheet.Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial _
    paste:=xlPasteValues
    Application.CutCopyMode = False
    Selection.Locked = True
    ActiveSheet.Protect Password:="lemon1"
    Sheets("Sheet5").Activate

    Selection.Delete
    Selection.Locked = True
    ActiveSheet.Protect Password:="lemon1"

    MsgBox "Holidays Have Been Cancelled", vbInformation
    End Sub

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    Is this what you wanted?
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    i was looking to amend the Cancel Macro code, please refer to sheet5 the cancel button at the top
    Attached Files Attached Files

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    Is your cancel code working?

    Your code says
    Copy Sheet5.Cells and paste Cancel.Cells and Delete Sheet5.Cells

    Is that what you want do do? or what?

    I just clicked on other button and getting error...

  15. #15
    Registered User
    Join Date
    04-27-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    36

    Re: Copying specific cells based on cell value "P" or "O" to sht1 or sht2

    What I want to happen is when a row or upto 20 rows are selected by a user. And when the cancel button is clicked the rows get moved to cancel sheet in the next empty rows. And sheet5 and cancel sheet remain in protected mode rather than unprotecting.

    I don't want to copy cell, but user selected rows. The code is not working as it brings up error code 1001: paste special Method range class failed
    Last edited by Ity007; 05-01-2016 at 04:05 PM.

+ 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] :confused: Auto pick "specific data" and put it in "specific cells" with date
    By pipsmultan in forum Excel Formulas & Functions
    Replies: 29
    Last Post: 08-27-2014, 03:31 AM
  2. Replies: 5
    Last Post: 01-23-2014, 11:02 AM
  3. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  4. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  5. [SOLVED] Data validation: allow entry into a cell if other three cells have "X", "Y" and "Z"?
    By RogerRangeRover in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-05-2013, 04:49 AM
  6. Change "Parent" cell based on results of multiple "Children" cells
    By ccowman in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 12-14-2012, 02:33 AM
  7. Replies: 0
    Last Post: 11-20-2012, 10:22 AM

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