+ Reply to Thread
Results 1 to 8 of 8

Date settings problem

Hybrid View

  1. #1
    Registered User
    Join Date
    06-11-2015
    Location
    Hong Kong
    MS-Off Ver
    365
    Posts
    6

    Date settings problem

    Hi,

    I'm still new to macro programming so I would appreciate some help with the following problem:

    The Cell H3 (and the following) should be the current date + 6 months

    So far I tried this and the I think the mistake must be somewhere in the colored code. The result which is displayed in H3 is 20150612 (and the following lines as well)

    Thanks for helping!

    Sub UpdateRBPUploadDAte()
    Dim NewDateX As String
    Dim FutureDateX As String
    Worksheets("RBP for Upload").Activate
    If ActiveSheet.AutoFilterMode Then
    ActiveSheet.AutoFilterMode = False
    End If
    NewDateX = Date
    NewDateX = Format(Date, "yyyymmdd")
    Range("G3") = NewDateX
    Range("G3").Select
    ActiveCell.Copy
    Range("G3", Range("G4").End(xlDown).Offset(1, 0)).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("G3").End(xlDown).Offset(0, 0).Select
    ActiveCell = clearcontent


    'FutureDateX = Date
    FutureDateX = DateAdd("m", 6, Date)
    FutureDateX = Format(Date, "yyyymmdd")
    Range("H3") = FutureDateX



    Range("H3").Select
    ActiveCell.Copy
    Range("H3", Range("H4").End(xlDown).Offset(1, 0)).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("H3").End(xlDown).Offset(0, 0).Select
    ActiveCell = clearcontent

    End Sub

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Date settings problem

    For the Colored lines, the result should actually be 20150612.

    Not sure what is the mistake there..
    Cheers!
    Deep Dave

  3. #3
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Date settings problem

    Need: OP wants 6 months from today
    so the whole red section can be replaced with

    Range("H3") = Format(DateAdd("m", 6, Date), "yyyymmdd")
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  4. #4
    Registered User
    Join Date
    06-11-2015
    Location
    Hong Kong
    MS-Off Ver
    365
    Posts
    6

    Re: Date settings problem

    Yes the result is 20150612, but the result I'm looking for is the current date +6 months, which means 20151212 (either 6 months or 183 days, doensn't matter)

  5. #5
    Registered User
    Join Date
    06-11-2015
    Location
    Hong Kong
    MS-Off Ver
    365
    Posts
    6

    Re: Date settings problem

    Thanks that solves the problem.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Date settings problem

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  7. #7
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Date settings problem

    Ooops I am sorry.. I missed it..

  8. #8
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    423

    Re: Date settings problem

    This line sets FutureDateX to today's date, which is not what you want

    FutureDateX = Format(Date, "yyyymmdd")

    This should do what you want (in one line instead of two)
    FutureDateX = Format(DateAdd("m", 6, Date),"yyyymmdd")

+ 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] Group and Outline Settings -Problem
    By Courtney in forum Excel General
    Replies: 2
    Last Post: 01-21-2015, 12:33 AM
  2. [SOLVED] Problem with settings dates for every saturday and sunday
    By Deasy in forum Excel General
    Replies: 9
    Last Post: 12-01-2013, 09:01 PM
  3. [SOLVED] Setting default to Value field settings and problem with refresh.
    By Reykjavik in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-23-2013, 08:29 AM
  4. fixed date format in case computer has different date settings e.g dd/mm or mm/dd
    By gwsampso in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-29-2013, 08:06 PM
  5. Replies: 1
    Last Post: 04-14-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