+ Reply to Thread
Results 1 to 33 of 33

Need to adapt some code to a new data set

  1. #1
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Need to adapt some code to a new data set

    Hi everyone,
    The monkeys need your help again. I have three files shared here and I will break them down for you.
    1. OldMacrosFile contains the code that currently works on my Mac for a different problem. This is a similar scenario but not exactly.
    2. FertileFemaleCount contains the data that I need moved over. Only column AJ. Each sheet is for a different monkey group.
    3. FertileTest is an example of the sort of file the code will populate information into.

    While many of the files that I will use this on are "like" FertileTest, there are some key differences, not in the headers, but in the columns. However, Column J will always be the populated column. J needs to be populated with data from FertileFemaleCount column AJ, based on how the FertileTest columns C (Date) and E (Group) match with FertileFemaleCount A (Date) and each respective sheet (these are based on the same group names of R1, R2, and PB).

    Does anyone think they can grab the code from the OldMacrosFile and adapt it accordingly? The only tricky thing about is that for the OldMacrosFile it needed to pull the information based on a day before the date listed. For this one, the actual date is what I need.

    Thanks in advance - i hope having the code already helps.
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    I'm confused. What do you want moved from which file to where in the other file? Column AJ is different things on tabs R1, R2 and PB in the FertileFemaleCount file. Where does this information wind up?

    The FertileFemaleCount has one record per day. the Fertile Test file has multiple records per day.

    Maybe you can trace several pieces of data from Count to Test as an example.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    I'm so sorry - I missed that entirely. Give me just a bit tonight to make this better with more information!
    Last edited by jeffreybrown; 07-02-2018 at 03:38 PM. Reason: Removed full quote!

  4. #4
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Red face Re: Need to adapt some code to a new data set

    Ok! I think I figured it out. In PB and in R2 AJ is the correct column (# females in fertile phase), this is column AS for the R1 tab.
    I uploaded a new file that has the first 129 rows filled in. Each of the Excel files that this code will let data flow into will always use J as the landing column.
    But the files themselves have varying numbers of rows based on what how R subsetted it for me. So some have 67,000 rows and others only have 35,000.
    In all of them, multiple rows will have the same date and the same group.

    If it helps, the rows on FertileTest are lines of behavior attached to a particular monkey in that group during a particular focal. So there
    will be multiple rows with seemingly similar information, but there are slight differences throughout the rest of the columns. (Which on the real
    files extend to like.. AZ.. lol)

    I hope this helps, please let me know if you need more and Thank You!
    PS - I changed up the code you wrote last time to work for a Mac, all the "/" are replaced with Application.Pathseparator
    Attached Files Attached Files

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    I notice that the name on the tab on this workbook has a .CSV extension. Does this mean that you opened the CSV file and saved it as an XLSX file?

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    This should work in both Macs and PCs. Fill in the path name to your source files in Cell B1 . Fill in the filenames in cells B2 and B3.

    I found it easier to build from scratch than to reverse engineer the code.

    I proceeded with the assumption that the matrix you want filled in is actually a CSV file. If it isn't just change the name in cell B3. It will work with either a CSV file or Excel file as long as the information you want is on the first sheet.

    The program works by copying the file in Cell B3 into the table in the Sheet called Fertile. It then opens the count file and gets the last row in each tab and last column in each tab. The last column is assumed to have the count you want.

    The program then goes down the list of dates in the table, picks the appropriate sheet and ranges in the source file and looks up the data. It records the number found if the value in column K is "F" or "f" - we don't want to record data for males. Whatever number comes across in column J will remain there. Also Column J is not changed if the date cannot be found in the source table.

    I hope this is what you want.

    For the purposes of testing I blanked out all the data in column J in the source file. I was able to confirm that rows with males or rows without a matching date were not affected,
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Thank you! Ok some info:
    1. The files were all initially saved as .xlsx and converted into CSV for R. So this code will be run on both CSV and Excel and it sounds like that should be ok - phew!
    2. Can you change J to show up on every row, whether male or female? It seems counter intuitive, but it is more important on the male rows because it serves as a control for their behavior. And we want it on the female rows, just in case it adjusts their behavior too.
    3. You mentioned "missing dates". But hopefully, there should not be any. Every date in the FertileTest file should be represented in the FertileFemale file. Fingers crossed this won't be a problem, but when I test it the first time, I will make sure sort the column and verify. Sometimes my stupid Excel files retain weird date formats and will mess stuff up.

    Again - thank you for hopping on to help me with such a complex problem. I really appreciate it.
    Last edited by jeffreybrown; 07-02-2018 at 03:38 PM. Reason: Removed full quote!

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    As for the males: when data is imported into the table it comes in with column J information filled in already. I only update information for females. Existing information for males remains unchanged.

    I only blanked out the data in the test data I was importing to make it easier to see that data for the males is unchanged. When you import real data you will have information there.

  9. #9
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Oh! Got it! I will test it out tonight when I get off work and will update you asap.

    Last edited by jeffreybrown; 07-02-2018 at 03:38 PM. Reason: Removed full quote!

  10. #10
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Sorry I didn't get back to you last night, I'll pm you the reason. I am messing with it now and I get a runtime error 76, path not found. But I checked the paths and the file names repeatedly. Not sure what to do.

  11. #11
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    You should not be getting this error message. I check for the existence of the paths to both files: if the path name does not exist, then you should get a dialog box telling you the path name and that it doesn't exist.

    Show me which line of code has the error and it may help me narrow down what might be causing it.

  12. #12
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Thank you! Here is a screen shot
    Screen Shot 2018-07-02 at 8.51.53 AM.png

  13. #13
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    Between the Function line and the If Dir() line add the following piece of code temporarily:

    Please Login or Register  to view this content.
    This bit of code should produce a dialog box with the file name being tested. It should have the colons in it instead of slashes.

    If it still has slashes, go to the top of the module and change the code indicated - apparently Application.PathSeparator isn't working and we'll have to hard code it.
    Please Login or Register  to view this content.
    You can remove the MsgBox after testing.

  14. #14
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    OK - here is the updated report. MsgBox showed slashes, I updated the code you suggested and tested again. I still get the same error in the same place and it still gives me slashes and not colons.
    Last edited by jeffreybrown; 07-02-2018 at 03:38 PM. Reason: Removed full quote!

  15. #15
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    Nothing is attached.

  16. #16
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Oh, I'm sorry, I didn't think I needed to attach anything. One second please, I'll screen shot the message box. Oops - I guess it gives ONE colon at the end that my tired eyes missed. Note to self that screen shots always help.
    After this, it pops up with the same fie not found run time error, highlighting the same row of code.
    Last edited by jeffreybrown; 07-02-2018 at 03:40 PM. Reason: Removed attachment with offensive language

  17. #17
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    The entries that you need to make in Cells B1, B2 and B3 must also have colons in them.

  18. #18
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    OH! OK - so they now look like this. (When I added : in front of B2 and B3, it added a double colon to the file name message box, so I removed those.)
    I get a new error as well, but the same line of code highlighted. Screen shots attached.
    Last edited by jeffreybrown; 07-02-2018 at 03:45 PM. Reason: Removed attachment with offensive language

  19. #19
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    I'm not familiar with the Mac directory structure so I did some research.

    I just pulled up information on the Mac File System. According to the article you can also use a forward slash. Set PS = "/" and define the paths and file names using forward slashes. I notice your names don't have spaces so you should not have issues with that.

  20. #20
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Need to adapt some code to a new data set

    @MermaidNiki,

    I removed all attached images with offensive language and removed extraneous quotes.

    It's possible more of the images were removed than necessary as I could not distinguish which one was the one with the offensive language.

    Please be careful what you post in the future!
    Last edited by jeffreybrown; 07-02-2018 at 03:51 PM.
    HTH
    Regards, Jeff

  21. #21
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Sorry Mod... It's how a frustrated phD labels her file folders. Can't really be helped.
    Last edited by jeffreybrown; 07-02-2018 at 05:16 PM.

  22. #22
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    I think I need to just use the Windows machines here on campus then, because nothing is working. And I went and looked at the old code to see if it could be adapted, but none of those fixes work either. I still get the device not found error. This is so frustrating because I know your code can work on a mac since the last one did with just Application.PathSeparator
    Last edited by jeffreybrown; 07-02-2018 at 05:16 PM.

  23. #23
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Need to adapt some code to a new data set

    Quote Originally Posted by MermaidNiki View Post
    Sorry Mod... It's how a frustrated phD labels her file folders. Can't really be helped.
    Frustrated or not, doesn't mean you should post that filth, so it can be helped.

  24. #24
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Quote Originally Posted by dflak View Post
    I'm not familiar with the Mac directory structure so I did some research.

    I just pulled up information on the Mac File System. According to the article you can also use a forward slash. Set PS = "/" and define the paths and file names using forward slashes. I notice your names don't have spaces so you should not have issues with that.
    Hey friend! I messed around with some code and rewrote some sections to get past the file name problem, only to run into issues with the Table Range code. Ugh. So, I ran to campus to use a Windows machine. This one gives me the following errors.

    WindowsError1a.png
    WindowsError1b.png

  25. #25
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Need to adapt some code to a new data set


    Hi !

    The #13 is an obviously error as per its message : the data expected does not match !
    So just compare the type of the variable and the type of the data …

  26. #26
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Quote Originally Posted by Marc L View Post

    Hi !

    The #13 is an obviously error as per its message : the data expected does not match !
    So just compare the type of the variable and the type of the data …
    Thank you, but the data DOES match. It worked on the test files I provided initially. This full file has all the exact same information, same headers, same columns, just 67K rows instead of only a few hundred. I did double check, but Date is column C. So I am a bit lost.

  27. #27
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    OH WAIT. I may have figured this out. Stay tuned.

  28. #28
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Quote Originally Posted by MermaidNiki View Post
    OH WAIT. I may have figured this out. Stay tuned.
    Nope

  29. #29
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Oh for Heaven's sake.... I see what it is...

    dflakk - I thought that the code would pull all the columns over into the Fertile sheet, not lock them into certain table headers. Not your fault at all, this has been a ridiculous and complex problem. And, I can work with this regardless, I just switched over the columns. Easy.

    So now the code runs with no errors, but column J, Fertile is totally blank =(

    Could it be this? Because I don't care if the monkey is male or female, the number needs to be put into the cell regardless.

    Please Login or Register  to view this content.
    YEP - I now have all cells filled in correctly except for the ones with males! If we can fix this, I will just run this macros on all my files on a Windows machine.
    Last edited by MermaidNiki; 07-02-2018 at 11:25 PM.

  30. #30
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    You hit in on the head. I am excluding the males. Remove the If / End If and the number will also be recorded for the males.

  31. #31
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Quote Originally Posted by dflak View Post
    You hit in on the head. I am excluding the males. Remove the If / End If and the number will also be recorded for the males.
    Please Login or Register  to view this content.
    I deleted this section of it and now nothing fills in - what am I doing wrong?
    Please Login or Register  to view this content.

  32. #32
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Need to adapt some code to a new data set

    This is what the code should look like in this section (note the commented out section) - you took out too much.
    Please Login or Register  to view this content.

  33. #33
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: Need to adapt some code to a new data set

    Quote Originally Posted by dflak View Post
    This is what the code should look like in this section (note the commented out section) - you took out too much.
    Please Login or Register  to view this content.

    I am now going to see if I can run this on the other 30 files and when they are successful, will mark this as resolved. Thank you!

+ 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. Adapt code
    By walber in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-13-2017, 06:37 PM
  2. Adapt code
    By walber in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 03-13-2017, 04:46 AM
  3. [SOLVED] Change code to select only specific range
    By julhs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-19-2017, 09:22 PM
  4. [SOLVED] Adapt VBA code to Copy only cells with Data
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2016, 11:45 AM
  5. [SOLVED] Adapt Code
    By PaulCooke in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-15-2015, 12:05 PM
  6. Adapt AutoFilter VBA code
    By jarnold231 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-05-2014, 11:48 PM
  7. Please help me to adapt this code.
    By Rob Hargreaves in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2005, 05:06 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