+ Reply to Thread
Results 1 to 8 of 8

If using macro to open up one xls to copy paste entire sheet over. It messes up dates

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    If using macro to open up one xls to copy paste entire sheet over. It messes up dates

    Hi
    I have to work with some spreatsheets that are generated by the system that we use at work. I would like to use a spreadsheet (lets say test.xls) and use a macro to open window that prompts me to choose xls file (lets call this test2.xls), then the macro should copy entire sheet (from test2.xls) and paste it back the original spreadsheet (test.xls - sheet "test"). I have a code to do this action. this is what I have:
    Please Login or Register  to view this content.

    The only problem is that the some of the dates that are stored from column M to column O get all messed up. Quite randomly to be honest. Some of the dates are recognised as text others as dates (or numbers). The ones that are recognised as dates or numbers rather than text are always aligned to right. Now these ones will swap over the month and the date like this - if its 31/03/2011 then it turns into 03/31/2011. The ones that are recognised as text remain the same ofcourse. I have had similar problems before but have managed to work around. Does anyone have an idea how to fix this. I would really like to copy info over this way. I have attached both example spreadsheets.


    Any help would be greately appreciated


    Cheers
    Rain
    Last edited by rain4u; 03-27-2011 at 09:16 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: If using macro to open up one xls to copy paste entire sheet over. It messes up d

    try:

    Please Login or Register  to view this content.



  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: If using macro to open up one xls to copy paste entire sheet over. It messes up d

    Maybe this
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: If using macro to open up one xls to copy paste entire sheet over. It messes up d

    I have to apologize first for not attaching the spreadsheets. As I did the posting at my workplace I rushed a bit. I no longer have access to those two specific example files but no worries I can quickly create a new ones. And this time I will name them properly otherwise its impossible for me to understand any offered codes. So the main file bears name YM26_converer and the system generated xls spreadsheet report bears name YM26. So after I have opened the file YM26_converter I would like to run macro to be prompted to select that system generated YM26 and then when selecting the file it should copy the entire active sheet to paste it to sheet called YM26_download. Alternatively it does not have to prompt with the window to select that YM26 file if it just copies the information over from that YM26 file that is in same folder as that YM26_converter. I aim to always call that report YM26. I would be happy with anything that will successfully copy over the info and keep the dates in intact.


    Quote Originally Posted by snb View Post
    try:

    Please Login or Register  to view this content.
    With this one, the code is all in red letters when pasted to VBA and it prompts with compile error
    Please Login or Register  to view this content.
    Though its missing somethingI have changed it for the time being and it is included with the newly attached files. Its currently like this:
    Please Login or Register  to view this content.
    With Roy's offered code I tried to change it to make it work with the new file names and sheet names but i get something wrong and it wont work. I have left it as it is on the attached spreadsheet.


    Can I ask either of yours help again
    Attached Files Attached Files

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: If using macro to open up one xls to copy paste entire sheet over. It messes up d

    This works for me
    Please Login or Register  to view this content.
    snb's code is missing a closing bracket

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: If using macro to open up one xls to copy paste entire sheet over. It messes up d

    Please Login or Register  to view this content.

    Hi guys
    I'm still having a problem with this Roy's offered macro. The code does copy over the information but it still gets the dates wrong. Please see my attachment. I have added this macro to xls spreadsheet. If you compare the column M on the source spreadsheet and on the destination spreadsheet you will see the problem. For an example take a look at M1 in source spreadsheet. It reads 18/05/2010, now when it is being transfered over to the destination sheet, then M1 reads 5/18/2010. The same problem applies to any cells that contain dates. Can some one run this macro and confirm it produces the same result. This is driving me nuts. Any help to remedy the problem would be very appreciated.



    Cheers
    Rain
    Attached Files Attached Files

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: If using macro to open up one xls to copy paste entire sheet over. It messes up d

    The dates look identical to me in both the original and the imported sheets

  8. #8
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: If using macro to open up one xls to copy paste entire sheet over. It messes up d

    Quote Originally Posted by royUK View Post
    The dates look identical to me in both the original and the imported sheets
    I reckon this could be because of my home PC. My Windows language and region was first setup as Estonia and I have changed it now. Because I swear i didn't have the problem at work PC. Also at work we have office 2003 while I have 2002. I will try to install 2003 and see if it makes the difference. Need to dig out my **'s as I know I have it somewhere. Thank you for confirming that the macro works properly.


    EDIT:


    Problem solved. With Office 2003 everything is working fine! Thank you so much for the support!!!!
    Last edited by rain4u; 03-27-2011 at 09:15 AM.

+ 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