+ Reply to Thread
Results 1 to 2 of 2

Macro to change date as per business days and its format daily in a column

  1. #1
    Registered User
    Join Date
    06-21-2016
    Location
    India
    MS-Off Ver
    office 10
    Posts
    7

    Macro to change date as per business days and its format daily in a column

    Hey guys!

    Well i have this excel macro that im working on which will automate a lengthy process.

    The macro currently does this : Takes raw data, changes its date daily and makes it in mm/dd/yyyy format, create 7 different excel files and save them in a location.

    Now i have everything working, but this darn date issue wont fix. Sometimes it works but sometimes it fails.

    The issue is I have to run the excel file in a remote desktop virtual machine and then after the output files are made, copy them into another remote desktop VM and use it there. It midst all this, the files get buggy and the dates dont come out right.


    Here is how the date comes in the raw file. https://www.dropbox.com/s/r114ucp8kg...lpme.xlsx?dl=0

    This excel file just has the date column of my file.

    Now here is the function i recorded in my macro on this column to get my desired mm/dd/yyyy format, but sometimes what happens is, they get converted into random 45123 numbers and sometimes it doesnt. I need a permanent fix for this. I recorded in my macro that it will go to general tab and change the column format to short date too, but that doesnt always work.

    Please Login or Register  to view this content.
    I use this code since i need to get the today's date -1 and it should only take business days. So if im using it on monday, i need friday.

    Now i am a newbie and dont know much about codes and stuff, but i try to wing it.


    Can someone help me out here?

  2. #2
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: Macro to change date as per business days and its format daily in a column

    The numbers that you are seeing is the conversion of the date to a long - i.e, the number of days after 1900 AD. You can convert them back from a long to a date:

    Dim lngDateVal as long
    Dim dDate as Date

    lngDateVal = Date
    ddate = lngDateVal

    You can also format that long as a date.

    Range("A1") = Format(lngDateVal, "mm/dd/yyyy")

    The format of the cell may override the way the date is displayed though, which is probably why you are having problems. in that case, try this:

    Range("A1").NumberFormat = "mm/dd/yy"

+ 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. Correct format to display business hours/days
    By M.e.R. in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-28-2015, 10:09 AM
  2. Replies: 4
    Last Post: 05-19-2014, 04:28 PM
  3. Replies: 7
    Last Post: 08-06-2013, 11:13 AM
  4. Replies: 1
    Last Post: 11-29-2010, 12:10 PM
  5. macro for changing the color or a row depending on the date - business days
    By leung.kevin8 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-21-2010, 03:07 PM
  6. Due date is 6 business days
    By Wzbell in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2007, 07:55 PM
  7. [SOLVED] Macro to highlight cells that are 5 business days from trade date
    By Jason via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2005, 04:06 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