Results 1 to 15 of 15

Thread: [RESOLVED] American Date Format - vba

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Resolved [RESOLVED] American Date Format - vba

    Hi Guys,

    Need a way to programatically/dyanmically shown today date in american format:-
    i.e 2/28/2006


    Must be formated as per bold above?


    Can anyone advise?

    Boris

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: American Date Format - vba - excel

    Any anyideas chaps ? I am trying to do this for excel vba.

    Boris

  3. #3
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: American Date Format - vba

    Code:
    Me.datebox.Value = Format(Now(), "mm/dd/yyyy")

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: American Date Format - vba

    Thanks for trying to help but its doesn't work basiaclly I'm trying to offset the date against column A which already contains random data. It doesn't like it for some reason, could you help me debug.

    VB Code:
    1. Sub Dates()
    2.  
    3. Dim filelength As Long
    4.  
    5. filelength = ActiveSheet.UsedRange.Rows.Count
    6.  
    7. Range("a1").Activate 'Activates a2
    8. For i = 1 To filelength
    9.  
    10. ActiveCell.Offset(0, 1).formula = Me.datebox.Value = Format(Now(), "mm/dd/yyyy")
    11. ActiveCell.Offset(1, 0).Activate
    12. Next i
    13. End Sub

    Thanks Boris.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: American Date Format - vba

    You cant have 2 equal signs on the same line.

    ActiveCell.Offset(0, 1).formula = Me.datebox.Value = Format(Now(), "mm/dd/yyyy")


    Whats the offset needing to be? the cell value plus a date value?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: American Date Format - vba

    Basically I have random data in column a (any length).

    Just need the american date format in column B offseted against the used range in column A.

    It need to fixed in column B and dynamic (live) each time the programe is run:-

    i.e 28/2/2006


    Must be exactly that format , no times etc.


    Thanks Very much, hope you can help


    Best Regards,

    Boris

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: American Date Format - vba

    Something like this but you may want to trap for the appropriate range first so it doesnt try to format invalid data from another column.
    VB Code:
    1. = Format(ActiveCell, "mm/dd/yyyy")
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: American Date Format - vba

    Hi M8,

    Nearly there I suppose but not quite the desired result, this may explain what I need , column A contains "BOB" (OR ANY RANDOM DATA not related). Column contains today date live (american style) as above.


    This is the output when I run the program:-

    cOLUMNA cOLUM B
    BOB 12/31/1899
    BOB 01/01/00
    BOB 02/01/00
    BOB 02/01/00
    BOB 02/01/00
    BOB 02/01/00
    BOB 02/01/00
    BOB 02/01/00
    BOB 02/01/00

    This is what I have:



    VB Code:
    1. [B]Sub Dates()
    2.  
    3. Dim filelength As Long
    4.  
    5. filelength = ActiveSheet.UsedRange.Rows.Count
    6. Range("a1").Activate 'Activates a2
    7. For i = 1 To filelength
    8. ActiveCell.Offset(0, 1).formula = Format(ActiveCell, "mm/dd/yyyy")
    9. ActiveCell.Offset(1, 0).Activate
    10. Next i
    11. End Sub[/B]

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: American Date Format - vba

    I dontsee where your changing the cell in your loop. It needs either to be referenced directly or each cell needs activating so the ActiveCell will change. Right now its always taking from the save value.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: American Date Format - vba

    This part of code is changing the row each time.

    VB Code:
    1. ActiveCell.Offset(1, 0).Activate


    Please bear with me , I'm a junior at coding:-

    I assume you get the "just" of what I'm trying to achieve, appreciate if you help finish what I'm trying to do.

    VB Code:
    1. [I]filelength = ActiveSheet.UsedRange.Rows.Count[/I]

    The above part of code is needed making it it only available to the used range which is what Iwant "integligence in knowing where to stop". I assume I need to use a loop.


    If you can thinking of a smarter way then great m8. Appreciate if you can add some comments where neccessary - so can understand and learn.

    Look forward to your response.

    Boris

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: American Date Format - vba

    Ok, lets re-think this. What is the date column (B) supposed to increment by? Increment by a day, a month, or a year?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: American Date Format - vba

    Hi it only meant to increment to today date live each time the program is run. Therefore it has to be dynamic.

    so today will be:-

    2/27/2006

    tommorrow will be

    2/28/2006


    Must be exactly this format.


    Hope this clarifies,
    B

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: American Date Format - vba

    VB Code:
    1. ActiveCell.Offset(0, 1).formula = Format(Date, "mm/dd/yyyy")
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    393

    Re: American Date Format - vba

    Thanks , you truly are a genius.

    You've savedme a sleeples night.

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: American Date Format - vba

    Glad someone is getting sleep as I am working on a sql db issue with only 3 hours sleep so far.

    Thanks for the props

    Ps, dont forget to Resolve your thread.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width