+ Reply to Thread
Results 1 to 11 of 11

VBA code to find cell contents within named range, copy to new row on another sheet

  1. #1
    Registered User
    Join Date
    10-01-2013
    Location
    san francisco
    MS-Off Ver
    Excel 2013
    Posts
    47

    VBA code to find cell contents within named range, copy to new row on another sheet

    i am good with formulas but unfamiliar with VBA.

    task: copy weekly results from Source sheet to a new row on Destination sheet, creating a 1-line journal entry of the weekly stats.
    1. cell G13 on SOURCE sheet contains the text string i want to find within RESULTS, a named range elsewhere on SOURCE sheet.
    2. find the cell in the range that contains this text, then use offset to copy the contents of the next column (same row), and paste to the first blank row after row 21, in column G on sheet "JOURNAL"

    i have about 30 of these to do, all within the same named range.

    i would like to assign to a button so when pressed, it copy/pastes all the values in one run.

    thank you in advance

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    • if you have 30 of them and want to do them all at once, are all 30 located in G13:G43, or...
    • what is the range of RESULTS?

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    Submit an example workbook which clearly demonstrates what you would like to occur.

  4. #4
    Registered User
    Join Date
    10-01-2013
    Location
    san francisco
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    thank you for the interest. this is the full scope of what i want to do:

    if there is a tick in SOURCE column H, and column G matches column A, then copy cell in column B to latest week on DESTINATION sheet in appropriate column. otherwise if there is a tick in col H but columns do not match, stop and return an error. continue for remaining cells.

    please lmk if i can explain further. thanks.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    I am still a little fuzzy on a couple of the fine points. How does this work for you?

    Please Login or Register  to view this content.
    Last edited by stnkynts; 02-23-2015 at 07:17 PM.

  6. #6
    Registered User
    Join Date
    10-01-2013
    Location
    san francisco
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    wow this is beautiful. error checking and everything. thank you very much!!

    i will study it and try to learn something from it.
    cheers

  7. #7
    Registered User
    Join Date
    10-01-2013
    Location
    san francisco
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    i am getting an Excel crash as i adapt this for more data records. i think it happens when there are not sufficient columns on the Destination sheet. can you include this factor in the error checking ?

  8. #8
    Registered User
    Join Date
    10-01-2013
    Location
    san francisco
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    i think the crash was related to a MsxBox i tried to add at the end, alerting that the Copy was successful.
    i had: MsgBox "Records copied." just before the end line of Application.ScreenUpdating = True

    also, how can i modify this to avoid looking in rows 1-7 (and start looking in row 8) ? thanks.

  9. #9
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    The code does not increase the columns on Dest sheet when compiling records and instead searches for a match in the existing columns, hence, I doubt the crash would happen there. What line was highlighted during crash. (Note: It will crash if you have no "x" or "X" in any row in column H but I don't see why you would run the code without at least one "x" so I didn't add the extra code)

    Amended code for starting at row 8 and added Msgbox
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-01-2013
    Location
    san francisco
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    not sure. haven't been able to repeat the crash since i removed the MsgBox line i added. Excel exits immediately without time to see any kind of line highlighting


    i am widening the scope of this a bit, need to move some columns around etc. there are 120+ records for each week and i'm not sure which i can eliminate. i wish i understood the code better so i could adapt it myself. but this is rather advanced for me. if you feel like explaining what the lines do, that would be great but no pressure.
    i will report back after i play with it a bit more. thanks again.

  11. #11
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA code to find cell contents within named range, copy to new row on another sheet

    I can explain the code if you want, but I don't know if my explanation skills are good enough to help you understand. Let me know if you still want explanation.

    If you submit your actual workbook, after you get done rearranging things, we may be able to get you better and more encompassing code.

+ 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] Combine Cell Contents with a Named Range
    By barnett2000 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-08-2013, 01:40 PM
  2. Code to find named range doesn't find the correct field range?
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-12-2012, 05:54 PM
  3. [SOLVED] Goto a named range using the contents of the active cell
    By Brian C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2006, 12:14 AM
  4. Copying contents of w/s drop down boxes to another sheet and creating a named range?
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-20-2006, 02:45 PM
  5. Finding a named range based on cell value and copy/paste to same sheet?
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2006, 06:25 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